[FIXED] While using GetMaterialApp fontFamily for the Theme is not Changing

Issue

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
enter image description here

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.

Solution

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

Answered By – Ranjith Kumar K

Answer Checked By – Gilberto Lyons (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published