Replace all element by image in flutter - flutter

I try to replace all patterns in a string by Flutter Image.network.
I do this:
String text = ":smiley: very goog"
text.replaceAll(":smiley:", Image.Network(src))
It does not work because replaceAll second argument must a text not a widget.

Related

Display Int or Double Widget Equivalent to Text()?

I want to display a double (or int) similar to how you would a string with a Text() widget. Is there an equivalent to this widget for ints or doubles in Flutter? Sorry if this is obvious, but I could not find anything.
Text("${<Your double/int variable>"})
You use a Text widget for this as well, simply use string interpolation to display your variables as a String:
final int two = 2;
final double pi = 3.14;
return Text("$two is an integer, and $pi is a double.");
You can also use the toString() method on any object in Dart (which is what the string interpolation above does implicitly). So if you want to print a double by itself, it's possible to write:
Text(pi.toString());
More on Strings and interpolation

i want to make many different images but this just show up Exception has occurred. _TypeError (type 'Image' is not a subtype of type 'String')

i want to make many different images using listView builder
Image.asset takes a string not, in this case you can either have your widgets as
list a =[
'assets/myimage.png',
'assets/myimage.png']
or change the Image.asset in your listview to
as your list a =[] returns a widget of type Image.asset
return a[index]
You are using redundand Image.asset.
Your code at line 25:
return Image.asset(Image.asset('.../.../sth.png'))
Change 25 line to :
return a[index]
You can read more about this topic here:
https://docs.flutter.dev/development/ui/assets-and-images

Animating Text widget content based on change of variable

How can I animate the change from a Text widget with a particular String to a new String which is dynamic, i.e., I don't know what it'll be beforehand ?
For example, let the widget be Text('a'). Later I want it to animate to Text('b'), maybe a after a button being clicked by a user.
Store the user input in a variable and display it in the Text widget. For example,
var input = value;
inside the widget you can use Text('$input') or directly Text(input) to display it

how to add color to primitive string in flutter

want to know the simple way to add color in primitive string.
I have a primitive string something like below and i want to color it without adding any widget
String s = "this is a string"; // i want to color this string
Everything is a widget in Flutter. You should really just wrap your String in a Text and use the style property to change the color of the String. But what is your main goal by doing so ?
Text(yourString,
style: TextStyle(
color: Color(0xFF**Your hex code**)
),),

How to retrieve text data from Text Widget in flutter

I am a beginner in flutter, how do i get or retrieve data from text widget. I have done some practice for example
Text("18:00"),
var data=Text("18:00");
print(data);
At the end instead of getting "18:00" i am getting "Text("17:05")" at the output.
define this
var data = "18:00";
Text("18:00"),
print(data);
To retrieve data fom a Text widget,
var data=Text("18:00");
print(data.data);
This will give you the output "18:00" as per your requirement.
what do you want to do? if you want to get an input from user you should use text field or forms by setting controller to it and get data from controller.
final myController = TextEditingController();
TextField(controller: myController),
var data=mycontroller.getText();
or if you want just get the text of text widget just set that text to a variable then pass it to widget.
String data="18:00"
Text(data);