Reputation: 467
I am using Getx for my state management. So When I Change MaterialApp to GetMaterialApp, the fontFamily switched back to the default.
pubspec.yaml file
flutter:
uses-material-design: true
fonts:
- family: Sen
fonts:
- asset: assets/fonts/Sen-Regular.ttf
weight: 300
- asset: assets/fonts/Sen-Bold.ttf
weight: 700
and I have saved Sen.ttf files in the assets/fonts folder
main.dart
Widget build(BuildContext context) {
return GetMaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(
primary: kPrimaryColor,
secondary: kSecondaryColor,
),
fontFamily: "Sen"
)
debugShowCheckedModeBanner: false,
home: const MainScreen(),
);
}
If I switch back to MaterialApp font will work fine.
Any help will be appreciated, Thank You.
Upvotes: 1
Views: 2576
Reputation: 95
I had to move the fonts directory into the top-level directory so the path for the fonts in the pubspect.yaml file would be.
fonts/
instead of
assets/fonts
(I also had to correct the indentation in the pubspec)
Upvotes: 0
Reputation: 66
Once this happened to me while working with some google fonts.
I tried different methods, there is nothing wrong with GetMaterialApp()
Option 1:
flutter clean
to clear all data, then update all the packages, and then flutter pub get
Option 2:
Initialy this is what I did. In the textTheme, add TextStyle
for different types of text (headline1,bodyText1,etc)
fontFamily: "Sen",
textTheme: const TextTheme(
headline1: TextStyle(
fontSize: 96.0,
fontWeight: FontWeight.w300,
fontFamily: 'Sen',
color: kPrimaryTextColor,
)
Option 3:
If nothing works, try flutter upgrade
Upvotes: 0
Reputation: 4767
I have tried using the minimal code but everything works for me. The font changes as you can see in the VIDEO DEMO. I suggest you to clean the cache or update the packages version to latest
Example
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: RoutesName.homePage,
getPages: Routes.getPages(),
initialBinding: InitialBindings(),
theme: ThemeData(fontFamily: "Blaka"),
);
}
pubspec file
flutter:
uses-material-design: true
fonts:
- family: Blaka
fonts:
- asset: assets/fonts/Blaka/Blaka-Regular.ttf
Upvotes: 1