How to choose different font weights without specifying new family for each weight?
fonts: - family: Montserrat fonts: - asset: assets/fonts/Montserrat-Regular.ttf weight: 100 - asset: assets/fonts/Montserrat-Bold.ttf weight: 700 - family: MontserratBold fonts: - asset: assets/fonts/Montserrat-Bold.ttf
and the widgets:
child: Text( 'TEST', style: TextStyle( fontSize: 17.4, fontFamily: 'Montserrat', fontWeight: FontWeight.w700, color: Colors.black87, ), ),
..
child: Text( 'TEST2', style: TextStyle( fontSize: 17.4, fontFamily: 'MontserratBold', color: Colors.black87), ),
The actual Montserrat-Bold is only used with 'TEST2'. I have tried using 'Packages get' in pubspec.yaml and restarting the app.
The flutter recent version v1.12.13 does not support the open type font(otf) directly. You have to convert the otf to true type font(ttf) somehow. You can use this third-party website to covert the font to ttf before using it in your project.
Importing font files in a project After downloading, we need to add the font files to our Flutter project. Create a folder named fonts in the root of the Flutter project. Next, move the Montserrat font files or . ttf files into the fonts folder that you just created.
From the docs we get this list of constants:
w100 Thin, the least thick
w200 Extra-light
w300 Light
w400 Normal / regular / plain
w500 Medium
w600 Semi-bold
w700 Bold
w800 Extra-bold
w900 Black, the most thick
So in pubspec you can define your custom font like this:
fonts: - family: Montserrat fonts: - asset: fonts/Montserrat-Regular.ttf - asset: fonts/Montserrat-SemiBold.ttf weight: 600 - asset: fonts/Montserrat-Bold.ttf weight: 700
and use it in your code like this:
final h1 = new TextStyle( fontSize: 24.0, fontWeight: FontWeight.w600 // semi-bold );
Font & style settings in pubspec are actually ignored: https://github.com/flutter/flutter/issues/36739#issuecomment-521806077
You need to check what weight is described in metadata inside Montserrat-Bold.ttf, perhaps it's not 700.
For displaying the metadata, you can use this site: https://fontdrop.info/, the font weight is displayed under Data/usWeightClass.
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