Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set textStyle of a Cupertino app in flutter

I have a CupertinoApp and I would like to apply a custom TextStyle to all the screen/object of my app. For example I would lie to set a font family to all Text widget & Dialog widget and use that font across all my app. I was hoping to set it once in CupertinoThemeData or CupertinoTextThemeData but so far I did not have joy.

Note: I am able to set style for each Text however I would like to set it once for all

like image 521
M4trix Dev Avatar asked Oct 07 '19 14:10

M4trix Dev


1 Answers

I've just run into this at the moment.

All I'm trying to do is colour text white, with general black backgrounds across the app (not font work).

The following has brought me some success:

return CupertinoApp(
  theme: new CupertinoThemeData(
    brightness: Brightness.dark,
    primaryColor: CupertinoColors.dark,
    barBackgroundColor: CupertinoColors.black,
    scaffoldBackgroundColor: CupertinoColors.black,
    textTheme: new CupertinoTextThemeData(
      primaryColor: CupertinoColors.white,
      brightness: Brightness.light,
      textStyle: TextStyle(color: CupertinoColors.white),
      // ... here I actually utilised all possible parameters in the constructor
      // as you can see in the link underneath
    ),
  ),
  // ...
)

Ref: CupertinoTextThemeData Constructor

I think you could extend my TextStyle(color: CupertinoColors.white) to apply fonts too. I intend to extract the TextStyle and ...ThemeData into separate classes to create a single place to edit them.

Hopefully this advances your position

like image 93
louisdeb Avatar answered Nov 15 '22 05:11

louisdeb