diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index 83563284..68b5cdd5 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -36,16 +36,8 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra ); NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? _nextcloudTheme; - final _platformBrightness = BehaviorSubject.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 with WidgetsBindingObserver, tray.Tra if (_platform.canUseWindowManager) { windowManager.removeListener(this); } - unawaited(_platformBrightness.close()); super.dispose(); } @override - Widget build(final BuildContext context) => StreamBuilder( - 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( - 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( + 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, + ); + }, ), ), ), diff --git a/packages/neon/neon/lib/src/utils/theme.dart b/packages/neon/neon/lib/src/utils/theme.dart index 4c498042..d59f58c7 100644 --- a/packages/neon/neon/lib/src/utils/theme.dart +++ b/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)