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. 25
      packages/neon/neon/lib/src/app.dart
  2. 30
      packages/neon/neon/lib/src/utils/theme.dart

25
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,15 +252,12 @@ 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(
Widget build(final BuildContext context) => OptionBuilder(
option: widget.globalOptions.themeMode,
builder: (final context, final themeMode) => OptionBuilder(
option: widget.globalOptions.themeOLEDAsDark,
@ -277,7 +266,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
builder: (final context, final themeKeepOriginalAccentColor) => StreamBuilder<Account?>(
stream: widget.accountsBloc.activeAccount,
builder: (final context, final activeAccountSnapshot) {
if (themeMode == null || !platformBrightnessSnapshot.hasData || themeOLEDAsDark == null) {
if (themeMode == null || themeOLEDAsDark == null) {
return Container();
}
@ -285,10 +274,15 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
return MaterialApp.router(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
themeMode: themeMode,
theme: getThemeFromNextcloudTheme(
_nextcloudTheme,
themeMode,
platformBrightnessSnapshot.data!,
Brightness.light,
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
),
darkTheme: getThemeFromNextcloudTheme(
_nextcloudTheme,
Brightness.dark,
oledAsDark: themeOLEDAsDark,
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
),
@ -298,6 +292,5 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
),
),
),
),
);
}

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