From 00c1411b9d2dcd34b2d7d7ed3f42219b620a7ab1 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 13 May 2023 15:57:35 +0200 Subject: [PATCH] neon: Fix theme switching --- packages/neon/neon/lib/src/app.dart | 43 +++++++++++-------- .../neon/neon/lib/src/blocs/accounts.dart | 4 +- .../neon/neon/lib/src/blocs/capabilities.dart | 4 -- packages/neon/neon/lib/src/utils/theme.dart | 2 - .../neon/lib/src/widgets/result_builder.dart | 2 +- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index cdd467f6..5168c83b 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -265,25 +265,30 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra } FlutterNativeSplash.remove(); - 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, - ), + return ResultBuilder( + stream: activeAccountSnapshot.hasData + ? widget.accountsBloc.getCapabilitiesBloc(activeAccountSnapshot.data!).capabilities + : null, + builder: (final context, final capabilitiesSnapshot) { + final nextcloudTheme = capabilitiesSnapshot.data?.capabilities.theming; + 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, + keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false), + oledAsDark: themeOLEDAsDark, + ), + routerDelegate: _routerDelegate, + ); + }, ); }, ), diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index 43e1ba52..b4922b8c 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -164,9 +164,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState CapabilitiesBloc getCapabilitiesBloc(final Account account) { if (_capabilitiesBlocs[account.id] != null) { - final bloc = _capabilitiesBlocs[account.id]!; - unawaited(bloc.refresh()); - return bloc; + return _capabilitiesBlocs[account.id]!; } return _capabilitiesBlocs[account.id] = CapabilitiesBloc( diff --git a/packages/neon/neon/lib/src/blocs/capabilities.dart b/packages/neon/neon/lib/src/blocs/capabilities.dart index 32fa1767..04c7fcd1 100644 --- a/packages/neon/neon/lib/src/blocs/capabilities.dart +++ b/packages/neon/neon/lib/src/blocs/capabilities.dart @@ -14,10 +14,6 @@ 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/utils/theme.dart b/packages/neon/neon/lib/src/utils/theme.dart index 4e929848..4441ad05 100644 --- a/packages/neon/neon/lib/src/utils/theme.dart +++ b/packages/neon/neon/lib/src/utils/theme.dart @@ -1,7 +1,5 @@ part of '../../neon.dart'; -final themeNotifier = ValueNotifier(null); - const themePrimaryColor = Color(0xFFF37736); ThemeData getThemeFromNextcloudTheme( diff --git a/packages/neon/neon/lib/src/widgets/result_builder.dart b/packages/neon/neon/lib/src/widgets/result_builder.dart index dfc3965f..c5d1dcee 100644 --- a/packages/neon/neon/lib/src/widgets/result_builder.dart +++ b/packages/neon/neon/lib/src/widgets/result_builder.dart @@ -7,7 +7,7 @@ class ResultBuilder extends StatelessWidget { super.key, }); - final BehaviorSubject> stream; + final BehaviorSubject>? stream; final Widget Function(BuildContext, Result) builder;