Flutter google_fonts package doesn't match for roboto flex font - flutter

Flutter doesn't render robotoFlex fonts Font weights Example Bold, W600, W700, W800, W900,
I'm using google_fonts for my project, I don't know what's wrong. Its working fine with other fonts like GoogleFont.lato and other
font comparison
child: Text(
'GoogleFonts.lato',
style: GoogleFonts.lato(
textStyle: const TextStyle(
fontSize: 17,
)),
).pV(5).pH(20),
),
Center(
child: Text(
'This is GoogleF.lato',
style: GoogleFonts.lato(
textStyle: const TextStyle(
fontSize: 26,
fontWeight: FontWeight.w900)),
).pV(5).pH(20),
),
Center(
child: Text(
'This is GoogleF.lato',
style: GoogleFonts.lato(
textStyle: const TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold)),
).pV(1).pH(20),
),
const SizedBox(
height: 35,
),
Center(
child: Text(
'GoogleFonts.robotoflex',
style: GoogleFonts.robotoFlex(
textStyle: const TextStyle(
fontSize: 17,
)),
).pV(5).pH(20),
),
Center(
child: Text(
'This is GoogleF.RobotoFlex',
style: GoogleFonts.robotoFlex(
textStyle: const TextStyle(
fontSize: 26,
fontWeight: FontWeight.w900)),
).pV(1).pH(20),
),
Center(
child: Text(
'This is GoogleF.RobotoFlex',
style: GoogleFonts.robotoFlex(
textStyle: const TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold)),
).pV(1).pH(20),
),
outPut Here you can see the difference google.lato font renders the font weight but roboto doesn't

Related

FontWeight not work with Chinese in Flutter

Below is my test code:
Text(
'I love 中国',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.w300,
color: Colors.red,
),
),
Text(
'I love 中国',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.w500,
color: Colors.red,
),
),
Result:
You can see with different fontWeight letter works but Chinese act the same.
How can I solve it?
My flutter is 3.3.2.
Note: run on iOS.
Flutter will search for a font on the host system that is closest to the specified font weight. But if the system only provides one font that handles the requested characters, then Flutter and Skia will synthesize a "fake bold" version of that font to handle other font weights.
Due to issue on github
Solution 1: Set theme in your MaterialApp:
theme: ThemeData(
fontFamily: "PingFang SC",
),
Solution 2: Set fontFamilyFallback where you need:
Text(
'I love 中国',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.w500,
color: Colors.red,
fontFamilyFallback: ["PingFang SC", "Heiti SC"],
),
),
Solution 3: Use DefaultTextStyle with fontFamilyFallback:
DefaultTextStyle(
style: TextStyle(
fontFamilyFallback: ["PingFang SC", "Heiti SC"],
color: Colors.red,
fontSize: 30,
),
child: Column(
children: [
Text(
'I love 中国',
style: TextStyle(
fontWeight: FontWeight.w400,
),
),
Text(
'I love 中国',
style: TextStyle(
fontWeight: FontWeight.w300,
),
),
Text(
'I love 中国',
style: TextStyle(
fontWeight: FontWeight.w500,
),
),
],
),
),

how to make a row responsive in flutter?

Hello i'm try to write this text " choose a one to modify the number " and the word "to modify " is with a different style text . my problem here is that the text is not responsive that mean there is not a return to next line if the phone has a small screen
how can i fix it and make this text in the center ?
Row(
children: const [
Text(
"Choose a one",
style: TextStyle(
fontSize: 17,
fontFamily: 'SFProRegular',
color: Color(0xFF000000),
),
),
Text(
"to modify",
style: TextStyle(
fontSize: 17,
fontFamily: 'SFProRegular',
color: Color(0xFFFF9E4F),
),
),
Text(
"the number",
style: TextStyle(
fontSize: 17,
fontFamily: 'SFProRegular',
color: Color(0xFF000000),
),
),
],
)
You can try using rich text, it will be like the following
RichText(
text: TextSpan(
text: "Choose a one",
style: TextStyle(
fontSize: 17,
fontFamily: 'SFProRegular',
color: Color(0xFF000000),
),
children: const <TextSpan>[
TextSpan(text: 'to modify',
style: TextStyle(
fontSize: 17,
fontFamily: 'SFProRegular',
color: Color(0xFFFF9E4F),
),
TextSpan(text: ' the number',
style: TextStyle(
fontSize: 17,
fontFamily: 'SFProRegular',
color: Color(0xFF000000),
),
),
],
),
)

make space between TextSpan

I am trying to make space between TextSpan
What is the best way to add space between TextSpan?
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
SizedBox widget can be used in between two widgets to add space between two widgets.
use the SizedBox by wrapping it with a WidgetSpan widgit
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
WidgetSpan(
child: SizedBox(width: 10),
),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
If you like to get maximum space between text, you might go for Row widget. For x amount of space inside RichText you can use
TextSpan(...),
WidgetSpan(child: SizedBox(width: x)),
TextSpan(...),
RichText(
text: const TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
WidgetSpan(child: SizedBox(width: 10)), ///this
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
You can use the height property on the TextStyle to create some spacing:
RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
height: 1.5, //USE THIS PROPERTY
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
SizedBox(height: 10),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
More info in the docs: https://api.flutter.dev/flutter/painting/TextStyle/height.html

big text in title and trailing

My code prints device characteristics. But if the text is too long, then the text is displayed ugly(as in the photo 1). I tried to fix it in different ways, but only title changes for me, trailing remains unchanged.
Can it be done in this way, if the text is long, then title is displayed in one line, and the next trailing (as in the photo 2)?
body: SingleChildScrollView(
child: Align(
alignment: Alignment.topCenter,
child: Column(
children: [
Container(
constraints: const BoxConstraints(maxWidth: 800),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(5.0),
),
child: Card(
child: Column(
children: [
ListTile(
title: const Text('Brand:', style: TextStyle(fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.brand} ', style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 20 ))),
const Divider(color: Colors.black, endIndent: 10, indent: 10),
ListTile(
title: const Text('Operation system:', style: TextStyle(fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.operation_system} ', style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 20 ))),
const Divider(color: Colors.black, endIndent: 10, indent: 10),
ListTile(
title: const Text('Version of OS:', style: TextStyle(fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.version_OS} ', style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 20 ))),
const Divider(color: Colors.black, endIndent: 10, indent: 10),
],
),
),
),
]
)
)
)
One option would be to remove trailing from ListTile and use RichText and TextSpan for title like so:
ListTile(
title: RichText(
text: TextSpan(
style: Theme.of(context).textTheme.headline6,
children: [
const TextSpan(
text: 'Version of OS: ',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 25,
),
),
TextSpan(
text: '${device.version_OS}',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 20,
),
),
],
),
),
),
Try below code hope its helpful to you.
Card(
child: ListTile(
leading: Text(
'Version of OS',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 20,
overflow:TextOverflow.ellipsis,
),),
title: Text('Your version with version 1.0'),
trailing: Text('Nokia'),
),
),

Flutter indentation on new line in ListBody

I have a ListBody which has a Text element and then a String which is returned by an API.
Such as..
Destination: $destination
Destination: London
However, if it is longer is spills over as such
Destination: London Paddington
Station
How is best to ensure that if the text is long enough to require a new line it is indented with the beginning on the String (i.e. The 'L' in 'London' is in-line)
Destination: London Paddington
Station
ListBody(
children: <Widget>[
RichText (
text: TextSpan(
children: <TextSpan> [
TextSpan(text: "\t\tDestination ", style: TextStyle(
fontSize: 18 ,
fontWeight: FontWeight.w400,
color: Color(0xff2F2F2F),
fontFamily: 'DMSans'
)
),
TextSpan(text: "$destination",
style: TextStyle(
fontSize: 18 ,
fontWeight: FontWeight.w600,
color: Colors.black,
fontFamily: 'DMSans'
)
),
Thank you
Why did you use a RichText ?
If it was only to render the "$destination" value in bold, it's a little bit overkill, and the following solution may be easier to implement.
Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Destination",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w400,
color: Color(0xff2F2F2F),
fontFamily: 'DMSans'),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(left: 12.0),
child: Text(
"London Paddington Station",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Colors.black,
fontFamily: 'DMSans'),
),
),
),
],
),
],
)
And the rendering will look like this
The most straightforward way is simply to display the text as a row of two elements, with crossAxisAlignment: CrossAxisAlignment.start
Like so:
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
'Destination: ',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w400,
color: Color(0xff2F2F2F),
fontFamily: 'DMSans',
),
),
Expanded(
child: Text(
'London Paddington Station',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Colors.black,
fontFamily: 'DMSans',
),
),
),
],
),
Note that it's important to wrap the long text in an Expanded widget - Otherwise, the text will simply overflow past the edge of the widget, rather than wrapping.
You can see a working example here: https://dartpad.dev/?id=80d0a8514577a65874c0e0ff7f2cb79c