I want to create a icon from a text like currency symbol. Currency symbols are not available in material icons and i don't want to use any third party library. I want to convert the text string like '$' to Icons and use them.
As per your requirement try below code hope its help to you:
Using \ character
Text(
'\$ Search',
),
Your Output Screen like->
Using Flutter Unicode character. You found Unicode character here
Text(
'Your \u{1F4B2} Symbol',
),
Your result screen like->
You can add any Symbol in between text
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text('Your'),
Icon(Icons.add),
Text('Icon'),
],
),
Your result screen like->
Or in VS Code you can used Windows + . keys and add any symbol on your need
Please try this one. 0024 is Unicode for $
Icon( IconData(0x0024, fontFamily: 'MaterialIcons'),size: 50, ))
Related
I am trying to put a specified unicode character into a Text widget, but only if there is a glyph available in the fontFamily font specified in the TextStyle.
What currently happens by design is the fontFamilyFallback font is checked for a glyph, and if not found then the system font is checked, then if still no glyph found a 'not found' style glyph is rendered instead - usually a box with an X inside (depends on system I think).
I wonder if there is a way to disable that fall-back or even better have a list of available glyphs before building the text widget?
Attached some example code, and the results of the code in a screenshot. The code uses two fonts available via google fonts, and attempts to output the euro unicode character \u20ac. You can see from the screenshot that Syne has a glyph at u20ac, but Arvo does not. This could also be validated in for example Windows Character map.
Flutter Code (nothing in texttheme other than fontsize):
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'No fontfamily, no fontfamilyfallback \u20AC',
),
Text(
'fontfamily Syne Tactile: \u20AC',
style: TextStyle(fontFamily: 'Syne'),
),
Text(
'fontfamily Arvo, no fontfamilyfallback \u20AC',
style: TextStyle(fontFamily: 'Arvo'),
),
Text(
'fontfamily Arvo, fontfamilyfallback: Syne Tactile \u20AC',
style:
TextStyle(fontFamily: 'Arvo', fontFamilyFallback: ['Syne']),
),
],
),
),
); }
pubspec.yaml:
fonts:
- family: Arvo
fonts:
- asset: assets/Arvo-Regular.ttf
- family: Syne
fonts:
- asset: assets/SyneTactile-Regular.ttf
Flutter Web Output
Found a bit of a hack/workaround. If I load the AdobeBlank font into the package, and use that as fontFamilyFallback, then a glyph with zero width is displayed. Not ideal (better to know before building), but sort of does the job.
Can also then try and determine width before building using something like this.
Hopefully there is a better answer out there still, as I'd much rather be able to load a font and know what glyphs are available somehow.
cv template and I want to edit it with flutter
Everything in Flutter is widgets, this image would be an Image widget in your Flutter app.
You can use Stack widget to put things over each other. so You can put image over an image by using Stack widget.
Unfortunately you can't edit text of an image in Flutter, Instead I would rather to edit this image (for putting image and editing text) by Photoshop for example and then implementing it as one piece widget in my Flutter app.
What I assess from your question is you want to have a layout like the one given in your link, right? For a circular image, you could use CircleAvatar. As for the text you could use the Text widget. Now put these widgets inside a Column or Row. You seem to be new to Flutter and I'd suggest you to get a good grip on the basics first. Anyhow, here's a little dummy code snippet you could extend to achieve what you're looking for
Column(
crossAxisAlignment: CrossAxisAlignment
.start, //if you want your widgets to align on left in your col
children: [
CircleAvatar(
radius: 70,
foregroundImage: AssetImage("pathToYourAssetImg"),
),
SizedBox(
height: 20, //set this to your intended value
),
Text( //you could also create a custom text widget and pass the arguments if you don't want to hardcode text widgets over & over again for all of your text
"yourText",
style: TextStyle(
color: Colors.black87,
fontSize: 20, //set this to your value
fontWeight: FontWeight.bold //if you want to have a bold text
),
),
],
);
I have a string and I would like to have an icon from the material icons displayed in that string. Currently, the only workaround is to use the standard emoji codes (e.g. '\u26A0').
I'm not quite sure how to do this. The reason I can't use a widget here is because I'm using a validator, and if the amount of characters are not met, the validator returns a string that reads out what the issue is. I'm trying to add a warning icon to it.
Would appreciate some help, thanks in advance!
The solution to your use case is WidgetSpan here is simple example of how to use it
Text.rich(
TextSpan(
children: <InlineSpan>[
TextSpan(text: 'call me'),
WidgetSpan(
child:Icon(Icons.phone)
),
],
)
),
I have an api from which I am fetching messages. These messages might contain emoji.
When it does contain emoji Text Widget is not displaying it correctly.
I just want to display them on the screen. Help if possible.
Thank you :)
class Message{
String text;
Message(){
this.text = get_data_from_api()['text'];
}
}
message = Message();
return Container(
child: Text(message.text),
);
No Displaying text with Emojis on Flutter
won't do it. I can do that but it only works if you have emoji in a string, that is explicitly plasing an emoji in string works fine for me. but when I am using something similar to the code above. I am getting, this
enter image description here
digging more into it I found that if I print my response on console it is
"ðððð"
and if I print a emoji it is 😭
So
I am using
Response.fromStream(await request.send())
from http/http.dart
So is that the problem ?
I did figured it out
I was taking data from an API. So while decoding for some reason it was not decoding utf-8 so what I needed to do was add
utf8.decode(response.bodyBytes);
in place of response.body and it was solved
Reference: Emoji and accent encoding in dart/flutter
If you have an emoji image explicitly present in the response from your API and you want to display it in your text, your should try adding WidgetSpan inside your RichText below is an example of how to do it :
RichText(
text: TextSpan(
children: [
TextSpan(
text: "Click ",
),
WidgetSpan(
child: Icon(Icons.add, size: 14),
),
TextSpan(
text: " to add",
),
],
),
),
In the above example they have used the material icon( Icon(Icons.add)). If you want to replace that from the image your get from the API, you can use ImageIcon instead of Icon widget. Follow this link to know how to use ImageIcon : https://www.woolha.com/tutorials/flutter-using-imageicon-widget-examples
Reference : Add image to RichText element
I want to add an icon with text. I didn't find any clear answer. Please suggest to me how to do this in a flutter. Just like this one.
Here are two approaches, depending on exactly what you want.
RichText with WidgetSpan
Using RichText you can mix TextSpans with WidgetSpans. WidgetSpan allows you to place any Flutter widget inline with the text. For example:
RichText(
text: TextSpan(
style: Theme.of(context).textTheme.body1,
children: [
TextSpan(text: 'Created with '),
WidgetSpan(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: Icon(Icons.airport_shuttle),
),
),
TextSpan(text: 'By Michael'),
],
),
)
Will give the following:
(Note: MaterialIcons did not include a heart when I answered, but does now with Icons.favorite)
This is a good general purpose solution, but for your specific example there's something simpler...
Emoji
Flutter's text supports Emoji out of the box. So you can do this:
Center(
child: Text(
'Created with ❤ ️by Michael',
maxLines: 1,
),
),
And you get this:
You can also use Unicode escapes in the string and get the same result:
'Created with \u2764️ by Michael'
Note that not all fonts have support for the full set of Emoji, so make sure you test on a variety of devices or use a specific font (see other answer below).
Regarding Emojis, in android not all emojis are supported (depending on OS version).
For full emoji compatibility you can use the google free font Noto Color Emoji at https://www.google.com/get/noto/#emoji-zsye-color
Add it to the fonts folder
add in pubspec.yaml
fonts:
- family: NotoEmoji
fonts:
- asset: fonts/NotoColorEmoji.ttf
weight: 400
use with TextStyle
Text("🤑", TextStyle(fontFamily: 'NotoEmoji'))