Flutter-Conditional formatting based on unique characters within a string. Is it possible? - flutter

I am new to flutter and have an application that uses a realtime database composed of long text strings. I am unable to separate the string itself into different sections and am wondering if it would be possible to apply conditional formatting with RichText(). I have seen that package of easy_rich_text and wanted to do something similar, but don't see an option to modify the string after the target text has been identified.
For example, if I had a string with "Apples are /red/ fruit", I could have flutter detect the string within the // and have font color red, while the remainder is black. Is this possible? And if so, How should I go about writing code for this?
Thanks in advance

Using the package flutter_html is probably the easiest way:
Widget widget = Html(data: 'Apples are <span style="color: #ff0000">red</span> fruits');

https://api.flutter.dev/flutter/widgets/RichText-class.html
Try this. It sounds like it should do the trick.
To be clear you need to parse the string yourself and thei render the results into the widget.

Related

Flutter `TextFormField` with RichText or `SpanText` in `initialValue`

I have some TextFormFields that I would like to have populated with RichText or SpanText instead of String in initialValue.
Is there a packaged that can help me with this?
The reason is that I am "highligting" phone numbers, emails and links by using this neat trick described here: https://stackoverflow.com/a/58361777/4475206 and it works like a charm when using it in a 'ordinary' Text.rich widget, but not so when using TextFormField when we need to set the initialValue parameter which just accepts String.
Checkout rich_input Package. It helps you to add strings with different text styles to text field

Flutter - Add color to portion of text with intl plugin for localization

I'm using the flutter plugin Intl for localize my app, everything work great, I can use variable in my strings like
//Somewere in code
String displayname = 'toto';
S.of(context).whyDeserveSecondChance(displayName),
Which prints the correct String in the correct language with the correct displayname.
My problem here, is that I want my displayname to appear on screen with a different color, I know that I can split my string in 3 but in some language it will just not work, so I have to keep it one string with the ${displayname}
I've search all day with no luck, does someone have a clue for me?

How to prevent writing before prefix in GWT valuebox

I am using GWT ValeBox with GWT Renderer to show amount with $ as prefix.
Now I want not to allow user to type any thing before dollar sign. I tried various GWT event handlers like ValueChangeHandler and some others but unable to achieve goal.
Still struggling for it. If anybody know good solution for it, please share here.
Regards,
The easiest would be to not include the currency as part of the value, but next to the field.
Alternatively, you could replace the value with a numeric-only value on focus, and reformat it as a currency on blur.
Couple of solutions:
Use a label before the valuebox. Label value will be $ and valuebox will contain the numeric value.
You can use empty text in the valuebox. Empty text will specify user to enter $ value.

zend form - Element Label in two line

I am extremely new to Zend Framework, In registration form, i need label text in two line. For Example:- In the case First name, I need to display like below:
First
Name:
How can i implement this? Please anyone help me!!!
By default, input fields labels are being escaped by Zend_View_Helper_FormLabel. However, you can easy switch this off:
$yourTextInputElement->getDecorator('label')->setOption('escape', false);
This way you can use labels as e.g. $yourTextInputElement->setLabel('First <br/> name');.
What about this nifty solution ?
http://jsfiddle.net/J67GD/
The best way is probably to use Description decorator, or subclass one of other standard ZF decorators.
Yanick's CSS solution might be a good choice too, depending what are you trying to do.

How to change the style of String in SWT?

I develop some features based on Eclispe GEF.
I want to create a label with some string.
for example:
new Label("This is a good test stensece")
Now, I want to get these effects "good" is in Bold font, and "test" is in italic.
It looks like can use some HTML way to implement that
So,is there any one knows that?
Thank you very much!
If you don't want to use StyledText, you could create multiple labels based on substrings of the original string, then use
labelName.setFont(Font font);
on each label to create different fonts for each portion.
StyledText! http://www.eclipse.org/articles/StyledText%201/article1.html