From 1e7ce247c902f2df7ab9126ac8bafe5167073759 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 11 May 2023 13:29:15 +0200 Subject: [PATCH] neon: cleanup changing of NextcloudTheme Signed-off-by: Nikolas Rimikis --- packages/neon/neon/lib/src/app.dart | 39 +++++++++---------- .../neon/neon/lib/src/blocs/capabilities.dart | 4 ++ packages/neon/neon/lib/src/pages/home.dart | 4 -- packages/neon/neon/lib/src/router.dart | 3 -- packages/neon/neon/lib/src/utils/theme.dart | 2 + 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index 68b5cdd5..cdd467f6 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -28,14 +28,8 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra late final _routerDelegate = AppRouter( navigatorKey: _navigatorKey, accountsBloc: _accountsBloc, - onThemeChanged: (final nextcloudTheme) { - setState(() { - _nextcloudTheme = nextcloudTheme; - }); - }, ); - NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? _nextcloudTheme; Rect? _lastBounds; @override @@ -271,22 +265,25 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra } 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), + return ValueListenableBuilder( + valueListenable: themeNotifier, + builder: (final context, final nextcloudTheme, final child) => 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, + keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false), + oledAsDark: themeOLEDAsDark, + ), + routerDelegate: _routerDelegate, ), - routerDelegate: _routerDelegate, ); }, ), diff --git a/packages/neon/neon/lib/src/blocs/capabilities.dart b/packages/neon/neon/lib/src/blocs/capabilities.dart index 04c7fcd1..de91d45c 100644 --- a/packages/neon/neon/lib/src/blocs/capabilities.dart +++ b/packages/neon/neon/lib/src/blocs/capabilities.dart @@ -14,6 +14,10 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents this._requestManager, this._client, ) { + capabilities.listen((final value) { + themeNotifier.value = value.data!.capabilities.theming; + }); + unawaited(refresh()); } diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index f3591072..d807df3a 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -5,12 +5,10 @@ const kQuickBarWidth = kAvatarSize + 20; class HomePage extends StatefulWidget { const HomePage({ required this.account, - required this.onThemeChanged, super.key, }); final Account account; - final Function(NextcloudTheme? theme) onThemeChanged; @override State createState() => _HomePageState(); @@ -48,8 +46,6 @@ class _HomePageState extends State { _capabilitiesBloc.capabilities.listen((final result) async { if (result.data != null) { - widget.onThemeChanged(result.data!.capabilities.theming); - // ignore cached version and prevent duplicate dialogs if (result.cached) { return; diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index 4e7ac622..e482c58f 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -5,11 +5,9 @@ class AppRouter extends RouterDelegate with ChangeNotifier, PopNavigato AppRouter({ required this.navigatorKey, required this.accountsBloc, - required this.onThemeChanged, }); final AccountsBloc accountsBloc; - final Function(NextcloudTheme? theme) onThemeChanged; final _globalPopups = const GlobalPopups(); @override @@ -41,7 +39,6 @@ class AppRouter extends RouterDelegate with ChangeNotifier, PopNavigato HomePage( key: Key(currentConfiguration!.id), account: currentConfiguration!, - onThemeChanged: onThemeChanged, ), ], ), diff --git a/packages/neon/neon/lib/src/utils/theme.dart b/packages/neon/neon/lib/src/utils/theme.dart index d59f58c7..0b0f174f 100644 --- a/packages/neon/neon/lib/src/utils/theme.dart +++ b/packages/neon/neon/lib/src/utils/theme.dart @@ -1,5 +1,7 @@ part of '../../neon.dart'; +final themeNotifier = ValueNotifier(null); + const themePrimaryColor = Color(0xFFF37736); ThemeData getThemeFromNextcloudTheme(