我正在尝试为我的应用制作自定义暗模式。 有没有办法设置按钮颜色,原色和其他主题颜色, 然后制作一个按钮在明暗模式之间切换?
`static get Black => true ? black_1D26 : black1_dark_0x161D;
静态得到淡紫色 => 真的? lightviolet_879B :lightviolet_dark_0x9CB1;
静态变蓝 => 真的? blue_0x2348FF : blue_dark_0x4B78`;
答案 0 :(得分:0)
您可以使用保存所选主题的 ThemeProvider,并且您可以在提供程序内部实现 getter 函数
答案 1 :(得分:0)
一种方法是:
创建一个包含 ThemeData 对象的类。 选择要更改的对象中的项目取决于您选择的主题。 像这样的东西,对于primaryColor,
bool lightTheme = true;
primaryColor : lightTheme ? Colors.blue : Colors.red,
在下面找到 ThemeData 类的所有属性。
ThemeData(
{Brightness? brightness,
VisualDensity? visualDensity,
MaterialColor? primarySwatch,
Color? primaryColor,
Brightness? primaryColorBrightness,
Color? primaryColorLight,
Color? primaryColorDark,
Color? accentColor,
Brightness? accentColorBrightness,
Color? canvasColor,
Color? shadowColor,
Color? scaffoldBackgroundColor,
Color? bottomAppBarColor,
Color? cardColor,
Color? dividerColor,
Color? focusColor,
Color? hoverColor,
Color? highlightColor,
Color? splashColor,
InteractiveInkFeatureFactory? splashFactory,
Color? selectedRowColor,
Color? unselectedWidgetColor,
Color? disabledColor,
Color? buttonColor,
ButtonThemeData? buttonTheme,
ToggleButtonsThemeData? toggleButtonsTheme,
Color? secondaryHeaderColor,
@Deprecated('Use TextSelectionThemeData.selectionColor instead. ' 'This feature was deprecated after v1.23.0-4.0.pre.') Color? textSelectionColor,
@Deprecated('Use TextSelectionThemeData.cursorColor instead. ' 'This feature was deprecated after v1.23.0-4.0.pre.') Color? cursorColor,
@Deprecated('Use TextSelectionThemeData.selectionHandleColor instead. ' 'This feature was deprecated after v1.23.0-4.0.pre.') Color? textSelectionHandleColor,
Color? backgroundColor,
Color? dialogBackgroundColor,
Color? indicatorColor,
Color? hintColor,
Color? errorColor,
Color? toggleableActiveColor,
String? fontFamily,
TextTheme? textTheme,
TextTheme? primaryTextTheme,
TextTheme? accentTextTheme,
InputDecorationTheme? inputDecorationTheme,
IconThemeData? iconTheme,
IconThemeData? primaryIconTheme,
IconThemeData? accentIconTheme,
SliderThemeData? sliderTheme,
TabBarTheme? tabBarTheme,
TooltipThemeData? tooltipTheme,
CardTheme? cardTheme,
ChipThemeData? chipTheme,
TargetPlatform? platform,
MaterialTapTargetSize? materialTapTargetSize,
bool? applyElevationOverlayColor,
PageTransitionsTheme? pageTransitionsTheme,
AppBarTheme? appBarTheme,
ScrollbarThemeData? scrollbarTheme,
BottomAppBarTheme? bottomAppBarTheme,
ColorScheme? colorScheme,
DialogTheme? dialogTheme,
FloatingActionButtonThemeData? floatingActionButtonTheme,
NavigationRailThemeData? navigationRailTheme,
Typography? typography,
NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
SnackBarThemeData? snackBarTheme,
BottomSheetThemeData? bottomSheetTheme,
PopupMenuThemeData? popupMenuTheme,
MaterialBannerThemeData? bannerTheme,
DividerThemeData? dividerTheme,
ButtonBarThemeData? buttonBarTheme,
BottomNavigationBarThemeData? bottomNavigationBarTheme,
TimePickerThemeData? timePickerTheme,
TextButtonThemeData? textButtonTheme,
ElevatedButtonThemeData? elevatedButtonTheme,
OutlinedButtonThemeData? outlinedButtonTheme,
TextSelectionThemeData? textSelectionTheme,
DataTableThemeData? dataTableTheme,
CheckboxThemeData? checkboxTheme,
RadioThemeData? radioTheme,
SwitchThemeData? switchTheme,
bool? fixTextFieldOutlineLabel,
@Deprecated('No longer used by the framework, please remove any reference to it. ' 'This feature was deprecated after v1.23.0-4.0.pre.') bool? useTextSelectionTheme}
)