Home > other >  How do I change the font or font size of the entire app in Flutter?
How do I change the font or font size of the entire app in Flutter?

Time:11-15

I'm making a settings page. What we support here is font change and font size change.

I would like to get the relevant material.

I think you should use a global variable to change the font.

If so, do I need to use a global variable to change the font size?

Give me a hint!

CodePudding user response:

Yes. You can set it as a global variable and pass it into the textTheme parameter of the ThemeData widget of your app. (You can save it to SharedPreferences so it won't be lost after app closure and retrieve it at startup)

CodePudding user response:

use theme widget and it will apply the customization of the theme in only child widget here you can write your custom theme for all child pages

    class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
          final AppBar appBar;
        
          CustomAppBar(): appBar = new AppBar();
        
          @override
          Widget build(BuildContext context) {
            return new Theme(
              child: appBar,
              data: new ThemeData(
//write your code for font here
)
            );
          }
        
          @override
          Size get preferredSize => appBar.preferredSize;
        }
  • Related