【问题标题】:Make a dialog ignore default theme in Flutter使对话框忽略 Flutter 中的默认主题
【发布时间】:2020-12-21 08:55:22
【问题描述】:

我正在使用 Flutter 创建一个应用程序。在我的 main.dart 文件中,我为这样的对话框指定了一个主题:

theme: ThemeData(
          primaryColor: Color(0xff2d2d2d),
          colorScheme: ColorScheme.dark(primary: Color(0xffe2e2e2)),
          accentColor: Color(0xffe2e2e2),
          dialogTheme: DialogTheme(
            backgroundColor: Color(0xff2d2d2d),
            titleTextStyle: TextStyle(
                fontWeight: FontWeight.w500,
                fontSize: 16,
                color: Color(0xffe2e2e2)),
          ),
        )

一切正常,但我的应用中有一些页面颜色相反。我使用searchable_dropdown 包在其中一个下拉列表中放置了一个下拉列表,它创建了一个包含国家列表的对话框,但它采用了该主题的所有颜色。有没有办法让它以某种方式忽略默认主题并提供另一个主题?

这是下拉菜单的代码:

SearchableDropdown.single(
          items: countries.map<DropdownMenuItem<String>>((country) {
            return (DropdownMenuItem<String>(
                child: Text(country['name']), value: country['name']));
          }).toList(),
          value: _country,
          searchHint: null,
          onChanged: (value) {
            setState(() {
              _country = value;
            });
          },
          dialogBox: false,
          isExpanded: true,
          menuConstraints: BoxConstraints.tight(Size.fromHeight(350))),

【问题讨论】:

    标签: flutter dialog flutter-layout


    【解决方案1】:

    您可以做的是,只需覆盖默认主题并在 textstyle 属性中传递您的自定义主题。

    Theme.of(context).textTheme.copyWith()
    
    

    【讨论】:

      猜你喜欢
      • 2011-09-02
      • 1970-01-01
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 2023-01-08
      • 1970-01-01
      • 1970-01-01
      • 2017-06-23
      相关资源
      最近更新 更多