Skip to content

Commit 1816786

Browse files
committed
theme [nfc]: Add debugFollowPlatformBrightness, to use in a test
1 parent 88bdf69 commit 1816786

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

lib/widgets/theme.dart

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,50 @@ import 'content.dart';
55
import 'stream_colors.dart';
66
import 'text.dart';
77

8+
/// In debug mode, controls whether the UI responds to
9+
/// [MediaQueryData.platformBrightness].
10+
///
11+
/// Outside of debug mode, this is always false and the setter has no effect.
12+
// TODO(#95) when dark theme is fully implemented, simplify away;
13+
// the UI should always respond.
14+
bool get debugFollowPlatformBrightness {
15+
bool result = false;
16+
assert(() {
17+
result = _debugFollowPlatformBrightness;
18+
return true;
19+
}());
20+
return result;
21+
}
22+
bool _debugFollowPlatformBrightness = false;
23+
set debugFollowPlatformBrightness(bool value) {
24+
assert(() {
25+
_debugFollowPlatformBrightness = value;
26+
return true;
27+
}());
28+
}
29+
30+
831
ThemeData zulipThemeData(BuildContext context) {
9-
final designVariables = DesignVariables();
32+
final DesignVariables designVariables;
33+
final List<ThemeExtension> themeExtensions;
34+
Brightness brightness = debugFollowPlatformBrightness
35+
? MediaQuery.of(context).platformBrightness
36+
: Brightness.light;
37+
switch (brightness) {
38+
case Brightness.light: {
39+
designVariables = DesignVariables();
40+
themeExtensions = [ContentTheme.light(context), designVariables];
41+
}
42+
case Brightness.dark: {
43+
designVariables = DesignVariables(); // TODO(#95)
44+
themeExtensions = [ContentTheme.dark(context), designVariables];
45+
}
46+
}
47+
1048
return ThemeData(
49+
brightness: brightness,
1150
typography: zulipTypography(context),
12-
extensions: [ContentTheme.light(context), designVariables],
51+
extensions: themeExtensions,
1352
appBarTheme: AppBarTheme(
1453
// Set these two fields to prevent a color change in [AppBar]s when
1554
// there is something scrolled under it. If an app bar hasn't been
@@ -57,6 +96,7 @@ ThemeData zulipThemeData(BuildContext context) {
5796
// Or try this tool to see the whole palette:
5897
// https://m3.material.io/theme-builder#/custom
5998
colorScheme: ColorScheme.fromSeed(
99+
brightness: brightness,
60100
seedColor: kZulipBrandColor,
61101
),
62102
scaffoldBackgroundColor: designVariables.mainBackground,

0 commit comments

Comments
 (0)