SOLVED: I'm still not sure what the problem was, but I fixed it by simply creating a new Flutter project, getting the fonts set up in the new project, and then just pasting my .dart files into the new project. Even though everything was exactly the same (as far as I can tell) it worked fine. Go figure.
I'm trying to use custom fonts in my app without success.
This is the fonts section of my pubspec.yaml file:
fonts:
- family: Muli
fonts:
- asset: fonts/Muli-Light.ttf
- family: LibreBaskerville
fonts:
- asset: fonts/LibreBaskerville-Regular.ttf
And in my app:
Widget _sectionTitle(String text) {
return Container(
padding: EdgeInsets.fromLTRB(25.0, 0.0, 25.0, 5.0),
child: Text(text,
style: new TextStyle(fontFamily: 'Muli', fontSize: 50.0),
));
}
Widget _sectionText(String text){
return Container (
padding: EdgeInsets.fromLTRB(25.0, 0.0, 25.0, 15.0),
child: Text(text, style: TextStyle(fontFamily: 'LibreBaskerville', fontSize: 20.0)),
);
}
Among the things I've tried (multiple times):
- Deleting the installed file from the emulator
- running from Android Studio vs running from VSCode
- moving the .ttf files to different folders
- downloading other fonts
- using an online YAML validator
- flutter clean
I'm assuming there's something amiss with the pubspec.yaml file, but I can't see what it might be.
Any suggestions would be much appreciated. Thx.
EDIT: Just tried creating a new default Flutter app with the same Pubspec.yaml font info. I added the custom font to the MaterialApp widget and it works ... so maybe the problem is not the yaml.