【问题标题】:Flutter: How to avoid flutter to automatically change text colorFlutter:如何避免flutter自动改变文本颜色
【发布时间】:2019-09-30 11:30:59
【问题描述】:

如果我在颤动中使用较浅的颜色作为原色,所有文本都会自动变黑。如果我选择深色原色,应用程序中的所有文本都会变为白色。

我知道他们选择了一种合适的颜色,因为对于文本颜色来说颜色可能太暗或太亮,这可能会让眼睛感到恼火,但我仍然想避免这种行为。

我知道我可以浏览所有文本主题并尝试设置它们,但我想尽可能避免这种情况,因为很难找到所有并正确设置它们。

    child: MaterialApp(
    title: 'Test App',
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      brightness: Brightness.light,
      primaryColor: Colors.teal[200], // All text is black
      primaryColor: Colors.teal[800], // ALL text is white

    ),

问题:如何避免根据我的原色自动改变颜色?我可以只在一个地方选择一种或另一种文本颜色吗?

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    尝试添加

    primaryTextTheme: Typography().black, // or white
    

    主题数据

    【讨论】:

    • 谢谢,我会接受这个,因为它确实影响了所有的文本。但是,除了受此影响的文本之外,还有更多颜色,所以我的问题实际上仍然存在。
    【解决方案2】:

    尝试添加primaryTextTheme

    ThemeData(
        primaryColor: Colors.teal[200],
        primaryTextTheme: TextTheme(
          title: TextStyle(color: Colors.white),
          subHead: TextStyle(color: Colors.white),
          body1: TextStyle(color: Colors.white),
          // etc...
        ),
    ),
    

    【讨论】:

    • 是的,我以前玩过这个,但很难在其中正确设置所有值。因为实际上不仅是文本,其他强调色也会受到影响
    猜你喜欢
    • 2021-12-04
    • 2020-02-02
    • 2018-05-03
    • 1970-01-01
    • 2021-09-18
    • 2019-01-27
    • 2022-11-18
    • 2021-08-22
    • 2023-01-29
    相关资源
    最近更新 更多