【问题标题】:SwitchListTile background colorSwitchListTile 背景颜色
【发布时间】:2021-04-13 22:41:23
【问题描述】:

我正在使用这个 lightTheme 和 darkTheme,我希望 SwitchListTile 具有相同的背景颜色(lightTheme 主题的白色 SwitchListTile 背景和 RGB(27、39、55、1.0) DarkTheme 的 SwitchListTile 背景)

 lightTheme: ThemeData(
        primarySwatch: Colors.grey,
        primaryColor: Colors.white,
        brightness: Brightness.light,
        backgroundColor: const Color(0xFFE5E5E5),
        scaffoldBackgroundColor: Colors.white,
        accentColor: Colors.blueAccent,
        accentIconTheme: IconThemeData(color: Colors.white),
        dividerColor: Colors.white54,
      ),
      darkTheme: ThemeData(
        brightness: Brightness.dark,
        primarySwatch: Colors.grey,
        primaryColor: Color.fromRGBO(27, 39, 55, 1.0),
        backgroundColor: const Color(0xFF212121),
        scaffoldBackgroundColor: Color.fromRGBO(27, 39, 55, 1.0),
        accentColor: Colors.blueAccent,
        accentIconTheme: IconThemeData(color: Colors.black),
        dividerColor: Colors.black12,
      ),

我正在使用 lutter_settings_screens 包

Padding(
                    padding: const EdgeInsets.all(0.0),
                    child: SettingsGroup(
                      title: 'settings',
                      children: <Widget>[
                        SettingsContainer(
                          children: [
                            SwitchSettingsTile(
                              defaultValue: true,
                              settingKey: 'switch1',
                              title: 'switch1',
                              subtitle: 'switch1',
                              onChange: (value) {},
                            ),
                            SwitchSettingsTile(
                              defaultValue: true,
                              settingKey: 'switch2',
                              title: 'switch2',
                              subtitle: 'switch2',
                              onChange: (value) {},
                            ),
                          ],
                        ),
                      ],
                    ),
                  )

那么我在 ThemeData 或 SwitchListTile 中错过了哪些参数来实现这一点?附screenshot

screenshot

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    这可能不是您想要的,坦率地说,我不知道哪个主题属性会更改SwitchListTile 背景颜色,但是更改主题属性值也可能会影响其他一些 UI 颜色,因此您可能需要更新只有这样的 SwitchListTile 颜色:

    Ink(
      color: Colors.red,
      child: SwitchListTile(
        value: false,
        title: Text('Switch'),
        onChanged: (val) {},
      ),
    )
    

    【讨论】:

    • 谢谢@dshukertjr,我正在使用 lutter_settings_screens 包中的 SwitchSettingsTile,我检查了这个包没有颜色覆盖,所以这就是为什么我怀疑 ThemeData 中的某些东西(不确定),我已经测试了您对 SettingsGroup、SettingsContainer 和 SwitchSettingsTile 的建议,它不起作用,我用示例更新了主题
    • 覆盖背景颜色不起作用,因为这些小部件(SettingsGroup、SettingsContainer 和 SwitchSettings)被包裹在这个包中的 Material 内,我已经编辑包并从这些小部件中删除了 Material,现在它可以工作了,你也是知道我们如何为每个主题的 Material Widget 设置默认颜色吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 2015-11-29
    相关资源
    最近更新 更多