【问题标题】:Theme overwriting in Flutter does not work, used official exampleFlutter中的主题覆盖不起作用,使用官方示例
【发布时间】:2019-05-11 17:51:43
【问题描述】:

Flutter 使用 Theme 并扩展/覆盖它的官方示例,如图所示不起作用。

我使用了颤振升级和颤振医生,所以我的颤振是最新的并且工作正常。 我猜安卓模拟器也可以正常工作。
我也重新启动了我的电脑,但它没有帮助。

我使用了这个网站的代码:https://flutter.dev/docs/cookbook/design/themes

floatingActionButton 应该是黄色的,但我的按钮是青色的。所以覆盖不起作用。 (如果需要我可以添加图片,但我认为我的问题很清楚。)

theme: ThemeData(
        // Define the default Brightness and Colors
        brightness: Brightness.dark,
        primaryColor: Colors.lightBlue[800],
        accentColor: Colors.cyan[600],

        // Define the default Font Family
        fontFamily: 'Montserrat',

        // Define the default TextTheme. Use this to specify the default
        // text styling for headlines, titles, bodies of text, and more.
        textTheme: TextTheme(
          headline: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
          title: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
          body1: TextStyle(fontSize: 14.0, fontFamily: 'Hind'),
        ),
      ),
floatingActionButton: Theme(
        data: Theme.of(context).copyWith(accentColor: Colors.yellow),
        child: FloatingActionButton(
          onPressed: null,
          child: Icon(Icons.add),
        ),
      ),

【问题讨论】:

  • 你能添加浮动动作按钮的代码
  • 这样吗?还是声明?
  • 你的主题是否有参数brightness: Brightness.Dark,因为我认为它会覆盖强调色
  • 确实如此,但如果我删除它,它只会改变背景颜色。我把主要的主题代码放在问题中。

标签: flutter themes


【解决方案1】:

尝试运行 Flutter clean 并重新运行您的应用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 2014-03-26
    • 2023-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多