this is my code
RichText(
text: TextSpan(children: [
TextSpan(
text: 'flutterABC',
style: TextStyle(
fontSize: isDesktop(context) ? 64 : 32,
fontWeight: FontWeight.w800)),
TextSpan(
text: 'flutterABC',
style: TextStyle(
fontSize: isDesktop(context) ? 64 : 32,
fontWeight: FontWeight.w800,
color: Colors.indigo))
]),
),
like this. i use RichText and TextSpan.
when i run in chrome, i can't control align
if 'flutterABCflutterABC' is one line > align is center.
but if two line > align is start..
i want to always align center
how can i do?
Try this please
RichText(
text: TextSpan(
children:[
TextSpan(
text: 'flutterABC\n',
style: TextStyle(
fontWeight: FontWeight.w800)),
TextSpan(
text: 'flutterABC',
style: TextStyle(
fontWeight: FontWeight.w800,
color: Colors.indigo))
]),
),
you can use Column to this effect
but if you went to use RichText
you can use \n for newline
Related
I want to make specific letter to have a custom font or style in Flutter, is it possible to do that? I only saw tutorial on how to make specific word in Flutter to have custom style by using RichText. Is there anyway to make a specific letter instead of a word?
for example
𝒜n elephant
In this case the letter A will have a custom font but the letter n does not.
The text parameter in a TextSpan can be omitted. So for what you want, you can just use the children parameter and have the first child be a single character.
RichText(
text: TextSpan(
children: [
TextSpan(
text: 'L',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
const TextSpan(text: 'ike this?')
],
),
),
You can do like this :
Text.rich(
TextSpan(text: 'This is textspan ', children: <InlineSpan>[
TextSpan(
text: 'Widget in flutter',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
)
]),
)
You can customize it any way you want :D
String myString = "Helloooo";
String specialChar = "o";
RichText(
text: TextSpan(
children: myString.characters.map((e) {
return TextSpan(
text: e,
style: e == specialChar
? TextStyle(
color: Colors.red, fontWeight: FontWeight.bold, fontSize: 40)
: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold, fontSize: 50),
);
}).toList()));
I'd like to use Twemoji font in my Flutter app. I installed this font. But when I try to use it in TextSpan, I see monochromatic emoji instead of colored. How to fix it?
My code:
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: "Some text ", style: GoogleFonts.roboto(
fontSize: 24,
color: Colors.black,
)),
TextSpan(text: "🐣", style: TextStyle(
fontFamily: "TwitterColorEmoji",
fontSize: 24,
)),
]
)
)
I got it, Twemoji font works in all operating system but will currently only show color emoji in Firefox, Thunderbird, Photoshop CC 2017+, and Windows Edge V38.14393+. This is not a limitation of the font, but of the operating systems and applications.
As has been said, die to limits of operation system and applications, this font won't show colored emojies.
I think the best altenative way to show colored emojies is using WidgetSpan with SvgPicture like in code below:
RichText(
text: TextSpan(
children: [
TextSpan(
text: "Some text ",
style: GoogleFonts.roboto(
fontSize: 24,
color: Colors.black,
),
),
WidgetSpan(
child: SvgPicture.asset("assets/emojies/confused-face.svg"),
style: TextStyle(fontSize: 24),
),
],
),
),
How can i make paragraphs in flutter in a text widget?
It is all just one long text and it looks stupid
What I want:
Hello,
how are you?
What it is:
Hello, how are you?
Use \n for paragraphs, like this: Text('Hello,\n\nhow are you?')
another approach, use RichText:
RichText(
text: TextSpan(
text: 'Hello,',
style: TextStyle(color: Colors.black, fontSize: 18.0),
children: <TextSpan>[
TextSpan(
text: 'how are you?',
style: TextStyle(fontWeight: FontWeight.bold, )
),
],
),
)
i have a piece of code below and i wanted to style the text "From" differently, i.e, display it black and bold in colour. It should remain in the same format.
Thank you.
Text("From :" + " " + from, style: GoogleFonts.viga(
color: Colors.blue[800],
fontWeight: FontWeight.w500,
), /*TextStyle(color: Colors.blue[800],)*/
),
You can use the RichText and TextSpan classes to achieve this behavior.
RichText(
text: TextSpan(
text: 'From:',
style: TextStyle(color: Colors.black),
children: <TextSpan>[
TextSpan(text: ' $from', style: TextStyle(color: Colors.blue[800])),
],
),
)
You can read more about it here
I have an Arabic text in a pdf file. When I copy the text into Text Widget it becomes weird characters. When I checked the pdf file properties I found that it uses HQPB1, HQPB2, HQPB3, HQPB4 fonts, so I imported all of these fonts to my pubsec.yaml file. The problem is that I can use only one of these 4 fonts at a time but the pdf file uses all of these 4 fonts simultaneously.
this is the original text from pdf
when I added HQPB1.ttf only
when I added HQPB2.ttf only
So I want to include all of these 4 fonts in a Text so that each individual font should be used when it is needed as pdf does.
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: 'Hello ', style: TextStyle(fontFamily: "Serif", fontSize: 30, color: Colors.black)),
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.blue, fontSize: 30)),
TextSpan(text: ' world!', style: TextStyle(fontFamily: "Roboto", fontSize: 30, color: Colors.red)),
],
),
)
Output:
In order to have multiple styles on one Text widget you have to use RichText. RichText has a children[] so you can have custom TextStyle (which will use whatever font you want) for each TextSpan
Check it out here -> https://api.flutter.dev/flutter/widgets/RichText-class.html
const Text.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: 'Hello ',
style: TextStyle(
fontFamily: "Serif",
fontSize: 30,
color: Colors.black,
),
),
TextSpan(
text: 'bold',
style: TextStyle(
fontFamily: "Arial",
fontWeight: FontWeight.bold,
color: Colors.blue,
fontSize: 30,
),
),
TextSpan(
text: ' world!',
style: TextStyle(
fontFamily: "Roboto",
fontSize: 30,
color: Colors.red,
),
),
],
),
)