/
flex_theme_dark.dart
225 lines (220 loc) · 11.5 KB
/
flex_theme_dark.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/material.dart';
import '../../shared/const/app_color.dart';
import '../../shared/const/app_data.dart';
import '../../shared/controllers/theme_controller.dart';
/// This function calls [flexColorSchemeDark] and uses
/// [FlexColorScheme.toTheme] to return the [ThemeData] object represented by
/// the returned [FlexColorScheme] setup.
///
/// We do it this way and not directly, or by setting it all up with the
/// convenience extension helper [FlexThemeData.dark], because when we create
/// a standard Flutter SDK theme with [ThemeData.from] a [ColorScheme] factory,
/// we will use the same [flexColorSchemeDark] dark function to return
/// the [ColorScheme] it represents with its [FlexColorScheme.toScheme] method.
///
/// The [ThemeData.from] a [ColorScheme] will be used to demonstrate difference
/// using the exact same [ColorScheme], but using just default [ThemeData] with
/// no [FlexColorScheme] theming applied.
///
ThemeData flexThemeDark(ThemeController controller) =>
flexColorSchemeDark(controller).toTheme;
/// Create the FlexColorScheme object represented by our current
/// [ThemeController] configuration.
///
/// This setup may seem complex, but all the controller does is represent
/// configuration values selected in the UI that are input to a large number
/// of properties in [FlexColorScheme], so we can dynamically produce the
/// configured theme.
///
/// Normally you would probably only have a few properties offered as possible
/// features the user can change. Since this is a feature demo of almost
/// everything [FlexColorScheme] it is a bit wild.
///
/// This function returns the Dark theme mode data that we us in the
/// ThemesPlayground app.
///
/// The function only contains tutorial comments on topics not covered in the
/// almost identical `flexColorSchemeLight` function. Please see it for
/// more tutorial comments.
FlexColorScheme flexColorSchemeDark(ThemeController controller) {
final bool useBuiltIn = controller.schemeIndex > 2 &&
controller.schemeIndex < AppColor.schemes.length - 1;
final int flexScheme = controller.schemeIndex - 3;
final bool useScheme = useBuiltIn && !controller.useToDarkMethod;
// Workaround for issue https://github.com/flutter/flutter/issues/103864.
// TODO(rydmike): Remove when fix for issue #10386 has landed in stable.
final bool useFakeTypo2018 =
(controller.useSubThemes && !controller.useTextTheme) ||
(!controller.useSubThemes && !controller.useMaterial3);
final TextTheme? fakeM2TypographyTextTheme =
useFakeTypo2018 ? AppData.m2TextTheme : null;
final Typography alwaysM3Typography =
Typography.material2021(platform: controller.platform);
// End of fix variables for issue #10386
return FlexColorScheme.dark(
// Use scheme based config, when we are using a built-in `FlexScheme`
// based schemes.
scheme: useScheme ? FlexScheme.values[flexScheme] : null,
// Switch to using `FlexSchemeColor` when using 3 first custom schemes or
// the last one that is customizable.
colors: !useScheme ? AppColor.scheme(controller).dark : null,
usedColors: controller.usedColors,
surfaceMode: controller.surfaceModeDark,
blendLevel: controller.blendLevelDark,
appBarStyle: controller.appBarStyleDark,
appBarOpacity: controller.appBarOpacityDark,
transparentStatusBar: controller.transparentStatusBar,
appBarElevation: controller.appBarElevationDark,
tabBarStyle: controller.tabBarStyle,
darkIsTrueBlack: controller.darkIsTrueBlack,
swapColors: controller.swapDarkColors,
tooltipsMatchBackground: controller.tooltipsMatchBackground,
//
subThemesData: controller.useSubThemes
? FlexSubThemesData(
interactionEffects: controller.interactionEffects,
blendOnLevel: controller.blendOnLevelDark,
blendOnColors: controller.blendDarkOnColors,
blendTextTheme: controller.blendDarkTextTheme,
useFlutterDefaults: controller.useFlutterDefaults,
useTextTheme: controller.useTextTheme,
//
defaultRadius: controller.defaultRadius,
bottomSheetRadius: controller.bottomSheetBorderRadius,
textButtonRadius: controller.textButtonBorderRadius,
elevatedButtonRadius: controller.elevatedButtonBorderRadius,
outlinedButtonRadius: controller.outlinedButtonBorderRadius,
toggleButtonsRadius: controller.toggleButtonsBorderRadius,
//
textButtonSchemeColor: controller.textButtonSchemeColor,
elevatedButtonSchemeColor: controller.elevatedButtonSchemeColor,
outlinedButtonSchemeColor: controller.outlinedButtonSchemeColor,
toggleButtonsSchemeColor: controller.toggleButtonsSchemeColor,
switchSchemeColor: controller.switchSchemeColor,
checkboxSchemeColor: controller.checkboxSchemeColor,
radioSchemeColor: controller.radioSchemeColor,
unselectedToggleIsColored: controller.unselectedToggleIsColored,
//
inputDecoratorSchemeColor: controller.inputDecoratorSchemeColorDark,
inputDecoratorIsFilled: controller.inputDecoratorIsFilled,
inputDecoratorBorderType: controller.inputDecoratorBorderType,
inputDecoratorRadius: controller.inputDecoratorBorderRadius,
inputDecoratorUnfocusedHasBorder:
controller.inputDecoratorUnfocusedHasBorder,
inputDecoratorUnfocusedBorderIsColored:
controller.inputDecoratorUnfocusedBorderIsColored,
//
fabUseShape: controller.fabUseShape,
fabRadius: controller.fabBorderRadius,
fabSchemeColor: controller.fabSchemeColor,
snackBarBackgroundSchemeColor: controller.snackBarSchemeColor,
chipSchemeColor: controller.chipSchemeColor,
chipRadius: controller.chipBorderRadius,
cardRadius: controller.cardBorderRadius,
popupMenuOpacity: controller.popupMenuOpacity,
popupMenuRadius: controller.popupMenuBorderRadius,
//
dialogBackgroundSchemeColor: controller.dialogBackgroundSchemeColor,
dialogRadius: controller.dialogBorderRadius,
timePickerDialogRadius: controller.dialogBorderRadius,
appBarBackgroundSchemeColor:
controller.appBarBackgroundSchemeColorDark,
tabBarItemSchemeColor: controller.tabBarItemSchemeColorDark,
tabBarIndicatorSchemeColor: controller.tabBarIndicatorDark,
// BottomNavigationBar settings
bottomNavigationBarSelectedLabelSchemeColor:
controller.bottomNavBarSelectedSchemeColor,
bottomNavigationBarUnselectedLabelSchemeColor:
controller.bottomNavBarUnselectedSchemeColor,
bottomNavigationBarMutedUnselectedLabel:
controller.bottomNavBarMuteUnselected,
bottomNavigationBarSelectedIconSchemeColor:
controller.bottomNavBarSelectedSchemeColor,
bottomNavigationBarUnselectedIconSchemeColor:
controller.bottomNavBarUnselectedSchemeColor,
bottomNavigationBarMutedUnselectedIcon:
controller.bottomNavBarMuteUnselected,
bottomNavigationBarBackgroundSchemeColor:
controller.bottomNavBarBackgroundSchemeColor,
bottomNavigationBarOpacity: controller.bottomNavigationBarOpacity,
bottomNavigationBarElevation:
controller.bottomNavigationBarElevation,
bottomNavigationBarShowSelectedLabels:
controller.bottomNavShowSelectedLabels,
bottomNavigationBarShowUnselectedLabels:
controller.bottomNavShowUnselectedLabels,
// NavigationBar settings
navigationBarSelectedLabelSchemeColor:
controller.navBarSelectedSchemeColor,
navigationBarUnselectedLabelSchemeColor:
controller.navBarUnselectedSchemeColor,
navigationBarMutedUnselectedLabel: controller.navBarMuteUnselected,
navigationBarSelectedIconSchemeColor:
controller.navBarSelectedSchemeColor,
navigationBarUnselectedIconSchemeColor:
controller.navBarUnselectedSchemeColor,
navigationBarMutedUnselectedIcon: controller.navBarMuteUnselected,
navigationBarIndicatorSchemeColor:
controller.navBarIndicatorSchemeColor,
navigationBarIndicatorOpacity: controller.navBarIndicatorOpacity,
navigationBarBackgroundSchemeColor:
controller.navBarBackgroundSchemeColor,
navigationBarOpacity: controller.navBarOpacity,
navigationBarHeight: controller.navBarHeight,
navigationBarLabelBehavior: controller.navBarLabelBehavior,
// NavigationRail settings
navigationRailSelectedLabelSchemeColor:
controller.navRailSelectedSchemeColor,
navigationRailUnselectedLabelSchemeColor:
controller.navRailUnselectedSchemeColor,
navigationRailMutedUnselectedLabel:
controller.navRailMuteUnselected,
navigationRailSelectedIconSchemeColor:
controller.navRailSelectedSchemeColor,
navigationRailUnselectedIconSchemeColor:
controller.navRailUnselectedSchemeColor,
navigationRailMutedUnselectedIcon: controller.navRailMuteUnselected,
navigationRailUseIndicator: controller.navRailUseIndicator,
navigationRailIndicatorSchemeColor:
controller.navRailIndicatorSchemeColor,
navigationRailIndicatorOpacity: controller.navRailIndicatorOpacity,
navigationRailBackgroundSchemeColor:
controller.navRailBackgroundSchemeColor,
navigationRailOpacity: controller.navRailOpacity,
navigationRailElevation: controller.navigationRailElevation,
navigationRailLabelType: controller.navRailLabelType,
)
: null,
//
// Advanced color properties for seed generated ColorScheme's
// Use key color based M3 ColorScheme.
keyColors: FlexKeyColors(
useKeyColors: controller.useKeyColors,
useSecondary: controller.useSecondary,
useTertiary: controller.useTertiary,
keepPrimary: controller.keepDarkPrimary,
keepSecondary: controller.keepDarkSecondary,
keepTertiary: controller.keepDarkTertiary,
keepPrimaryContainer: controller.keepDarkPrimaryContainer,
keepSecondaryContainer: controller.keepDarkSecondaryContainer,
keepTertiaryContainer: controller.keepDarkTertiaryContainer,
),
useMaterial3ErrorColors: controller.useM3ErrorColors,
tones:
AppColor.flexTonesConfig(Brightness.dark, controller.usedFlexToneSetup),
//
// ThemeData properties passed along directly to ThemeData.
visualDensity: AppData.visualDensity,
fontFamily: controller.useAppFont ? AppData.font : null,
platform: controller.platform,
useMaterial3: controller.useMaterial3,
// Workaround for issue: https://github.com/flutter/flutter/issues/103864.
// TODO(rydmike): Remove when fix for issue #10386 has landed in stable.
typography: alwaysM3Typography,
// Workaround for issue: https://github.com/flutter/flutter/issues/103864.
// TODO(rydmike): Remove when fix for issue #10386 has landed in stable.
textTheme: fakeM2TypographyTextTheme,
primaryTextTheme: fakeM2TypographyTextTheme,
);
}