Browse Source

neon: cleanup theming

let the MaterialApp decide wich theme to use for a given brightness
Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/311/head
Nikolas Rimikis 2 years ago
parent
commit
8d82c93457
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 71
      packages/neon/neon/lib/src/app.dart
  2. 30
      packages/neon/neon/lib/src/utils/theme.dart

71
packages/neon/neon/lib/src/app.dart

@ -36,16 +36,8 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
);
NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? _nextcloudTheme;
final _platformBrightness = BehaviorSubject<Brightness>.seeded(WidgetsBinding.instance.window.platformBrightness);
Rect? _lastBounds;
@override
void didChangePlatformBrightness() {
_platformBrightness.add(WidgetsBinding.instance.window.platformBrightness);
super.didChangePlatformBrightness();
}
@override
void initState() {
super.initState();
@ -260,42 +252,43 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
if (_platform.canUseWindowManager) {
windowManager.removeListener(this);
}
unawaited(_platformBrightness.close());
super.dispose();
}
@override
Widget build(final BuildContext context) => StreamBuilder<Brightness>(
stream: _platformBrightness,
builder: (final context, final platformBrightnessSnapshot) => OptionBuilder(
option: widget.globalOptions.themeMode,
builder: (final context, final themeMode) => OptionBuilder(
option: widget.globalOptions.themeOLEDAsDark,
builder: (final context, final themeOLEDAsDark) => OptionBuilder(
option: widget.globalOptions.themeKeepOriginalAccentColor,
builder: (final context, final themeKeepOriginalAccentColor) => StreamBuilder<Account?>(
stream: widget.accountsBloc.activeAccount,
builder: (final context, final activeAccountSnapshot) {
if (themeMode == null || !platformBrightnessSnapshot.hasData || themeOLEDAsDark == null) {
return Container();
}
FlutterNativeSplash.remove();
return MaterialApp.router(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
theme: getThemeFromNextcloudTheme(
_nextcloudTheme,
themeMode,
platformBrightnessSnapshot.data!,
oledAsDark: themeOLEDAsDark,
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
),
routerDelegate: _routerDelegate,
);
},
),
Widget build(final BuildContext context) => OptionBuilder(
option: widget.globalOptions.themeMode,
builder: (final context, final themeMode) => OptionBuilder(
option: widget.globalOptions.themeOLEDAsDark,
builder: (final context, final themeOLEDAsDark) => OptionBuilder(
option: widget.globalOptions.themeKeepOriginalAccentColor,
builder: (final context, final themeKeepOriginalAccentColor) => StreamBuilder<Account?>(
stream: widget.accountsBloc.activeAccount,
builder: (final context, final activeAccountSnapshot) {
if (themeMode == null || themeOLEDAsDark == null) {
return Container();
}
FlutterNativeSplash.remove();
return MaterialApp.router(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
themeMode: themeMode,
theme: getThemeFromNextcloudTheme(
_nextcloudTheme,
Brightness.light,
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
),
darkTheme: getThemeFromNextcloudTheme(
_nextcloudTheme,
Brightness.dark,
oledAsDark: themeOLEDAsDark,
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
),
routerDelegate: _routerDelegate,
);
},
),
),
),

30
packages/neon/neon/lib/src/utils/theme.dart

@ -4,31 +4,21 @@ const themePrimaryColor = Color(0xFFF37736);
ThemeData getThemeFromNextcloudTheme(
final NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? nextcloudTheme,
final ThemeMode themeMode,
final Brightness platformBrightness, {
required final bool oledAsDark,
final Brightness brightness, {
required final bool keepOriginalAccentColor,
final bool oledAsDark = false,
}) {
final primaryColor = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color!) : themePrimaryColor;
late final Brightness selectBrightness;
switch (themeMode) {
case ThemeMode.system:
selectBrightness = platformBrightness;
break;
case ThemeMode.light:
selectBrightness = Brightness.light;
break;
case ThemeMode.dark:
selectBrightness = Brightness.dark;
break;
if (oledAsDark) {
assert(brightness == Brightness.dark, 'Brightness.dark is required for oledAsDark.');
}
final oledBackgroundOverride = selectBrightness == Brightness.dark && oledAsDark ? Colors.black : null;
final primaryColor = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color!) : themePrimaryColor;
final oledBackgroundOverride = oledAsDark ? Colors.black : null;
final keepOriginalAccentColorOverride = keepOriginalAccentColor ? primaryColor : null;
final colorScheme = ColorScheme.fromSeed(
seedColor: primaryColor,
brightness: selectBrightness,
brightness: brightness,
).copyWith(
background: oledBackgroundOverride,
primary: keepOriginalAccentColorOverride,
@ -37,7 +27,7 @@ ThemeData getThemeFromNextcloudTheme(
final fillColor = MaterialStateProperty.resolveWith((final states) {
if (states.contains(MaterialState.disabled)) {
return selectBrightness == Brightness.dark ? Colors.white38 : Colors.black38;
return brightness == Brightness.dark ? Colors.white38 : Colors.black38;
}
return colorScheme.primary;
@ -62,7 +52,7 @@ ThemeData getThemeFromNextcloudTheme(
),
popupMenuTheme: PopupMenuThemeData(
// TODO: Only needed until M3 popup menus are implemented
color: selectBrightness == Brightness.dark
color: brightness == Brightness.dark
? oledAsDark
? const Color(0xFF202020)
: const Color(0xFF404040)

Loading…
Cancel
Save