How to change the entire theme's text color in Flutter?

后端 未结 5 1856
既然无缘
既然无缘 2021-02-01 12:34

There is probably something obvious I\'m missing. Is there one property that can change the color of all the text in a Flutter app?

The way I am doing it now is

相关标签:
5条回答
  • 2021-02-01 12:43

    mine is working with this:

    return MaterialApp(
      theme: ThemeData(
        textTheme: TextTheme(
          bodyText2: TextStyle(
            color: Colors.white,
          ),
        ),
      ),
    );
    
    0 讨论(0)
  • 2021-02-01 12:49

    To provide an alternative that seems to work without setting all the Text styles directly is to change the style of the DefaultTextStyle at the place in the Widget tree to take effect

    return DefaultTextStyle(
      style: TextStyle(color: Colors.pink),
      child: _YOUR_WIDGETS_
    )
    
    0 讨论(0)
  • 2021-02-01 12:55

    I think TextTheme.apply is what you want. bodyColor will be applied to headline, title, subhead, button, body1, and body2. displayColor will be applied to display1 through display4, and caption. If you specify both bodyColor and displayColor and use the same color value, that will effectively change text colors on all text styles.

    Example:

    final newTextTheme = Theme.of(context).textTheme.apply(
      bodyColor: Colors.pink,
      displayColor: Colors.pink,
    );
    
    0 讨论(0)
  • 2021-02-01 12:55

    For the entire app, you can set textTheme property in the Material app widget.

    MaterialApp(
      theme: ThemeData(
        textTheme: TextTheme(
          bodyText1: TextStyle(),
          bodyText2: TextStyle(),
        ).apply(
          bodyColor: Colors.orange, 
          displayColor: Colors.blue, 
        ),
      ),
    ) 
    
    0 讨论(0)
  • 2021-02-01 13:06

    Maybe a bit late... but you can use this:

    ThemeData(
        primaryTextTheme: Typography(platform: TargetPlatform.iOS).white,
        textTheme: Typography(platform: TargetPlatform.iOS).white,
    )
    
    0 讨论(0)
提交回复
热议问题