Flutter not picking custom fonts based on fontWeight
From the docs we get this list of constants:
w100 Thin, the least thick
w400 Normal / regular / plain
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.
From my experiments, the weight system seems to be doing some clever things behind the scenes. Maybe it depends on the ttf or the device. I would bet though that
FontWeight.w900 might fall into the bold font.
In my code if I specify a weight of 100 (regular) and 200 (for bold), the bold font is not used until I ask for
FontWeight.w500. I can tell because I also ask for it in italics, and the bold ttf does not italicize for some reason regardless of weight. So while the weights do "thicken" the font programmatically, catching how and why they fall into a specific font seems to require some guess work.
I then tried with 3 fonts: thin, regular and bold and set them to sensible weights in the pubspec.yaml of 100, 400 and 700 which are described in the docs as
normal / regular / plain and
bold, and now anything above
FontWeight.w400 uses bold.
Hopefully this helps, or someone more knowledgeable comes along