如何在 Flutter 中通过 ThemeData 设置 SwitchListTile 的 inactiveTrackColor 和 inactiveThumbColor 的颜色?

问题描述 投票:0回答:1

我可以为整个应用程序中使用的 SwitchListTile 设置非活动颜色,但是,在应用程序主题中设置它会简单得多(因为我有多个自定义主题)。

但是,我注意到这些颜色值无法传递到 SwitchThemeData 中,想知道我是否遗漏了什么?

例如我可以在各个 SwitchListTile 小部件中设置颜色。

    return SwitchListTile(
      inactiveTrackColor: Colors.grey,
      inactiveThumbColor: AppColors.lightGrey,...)

但想在 ThemeData 类中定义非活动颜色。

ThemeData(
  switchTheme: SwitchThemeData(
    thumbColor: MaterialStateProperty.all<Color>(AppColors.tealPrimary),
    trackColor: MaterialStateProperty.all<Color>(AppColors.tealDarkest),
    overlayColor: MaterialStateProperty.all<Color>(AppColors.lightGrey),
//// MISSING INACTIVE PROPERTIES HERE?
  ),
...
);

flutter material-design
1个回答
0
投票

我也有同样的问题,我也试过了,但是没用。

    switchTheme: SwitchThemeData(
      trackColor: MaterialStateProperty.resolveWith((states) {
        if (states.contains(MaterialState.disabled))
          return Colors.grey;
        return Colors.green;
      }),
  ),
© www.soinside.com 2019 - 2024. All rights reserved.