I want to show an icon in text widget. How do I do this ?
The following code only shows the IconData
Text("Click ${Icons.add} to add");
The simplest way to create a button with icon and text in Flutter is to use the new Material button called ElevatedButton with an icon constructor. ElevatedButton. icon() gives you the ability to add the icon and label parameter to the button.
You can wrap Icon() widget with InkWell or alternatively GestureDetector() widget to make icons clickable in your Flutter app.
“icon before text in flutter” Code AnswerFlutter has WidgetSpan() to add a widget inside the RichText(). You can treat the child of WidgetSpan like the usual widget.
Flutter has WidgetSpan()
to add a widget inside the RichText()
.
Example use:
RichText( text: TextSpan( children: [ TextSpan( text: "Click ", ), WidgetSpan( child: Icon(Icons.add, size: 14), ), TextSpan( text: " to add", ), ], ), )
Above code will produce:
You can treat the child of WidgetSpan
like the usual widget.
An alternative might be to use emoji.
In Dart, strings supports escape sequences for special characters. For unicode emoji, you can use \u and curly braces with emoji hex code inside. Like this:
Text('Click \u{2795} to add')
The result is:
You can find a complete unicode emoji list here: http://unicode.org/Public/emoji/1.0/emoji-data.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With