Browse Source

Merge pull request #320 from provokateurin/fix/theme-switching

neon: Fix theme switching
pull/296/head
Kate 2 years ago committed by GitHub
parent
commit
6531b2ada7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      packages/neon/neon/lib/src/app.dart
  2. 4
      packages/neon/neon/lib/src/blocs/accounts.dart
  3. 4
      packages/neon/neon/lib/src/blocs/capabilities.dart
  4. 2
      packages/neon/neon/lib/src/utils/theme.dart
  5. 2
      packages/neon/neon/lib/src/widgets/result_builder.dart

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

@ -265,25 +265,30 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
} }
FlutterNativeSplash.remove(); FlutterNativeSplash.remove();
return ValueListenableBuilder( return ResultBuilder<Capabilities?>(
valueListenable: themeNotifier, stream: activeAccountSnapshot.hasData
builder: (final context, final nextcloudTheme, final child) => MaterialApp.router( ? widget.accountsBloc.getCapabilitiesBloc(activeAccountSnapshot.data!).capabilities
localizationsDelegates: AppLocalizations.localizationsDelegates, : null,
supportedLocales: AppLocalizations.supportedLocales, builder: (final context, final capabilitiesSnapshot) {
themeMode: themeMode, final nextcloudTheme = capabilitiesSnapshot.data?.capabilities.theming;
theme: getThemeFromNextcloudTheme( return MaterialApp.router(
nextcloudTheme, localizationsDelegates: AppLocalizations.localizationsDelegates,
Brightness.light, supportedLocales: AppLocalizations.supportedLocales,
keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false), themeMode: themeMode,
), theme: getThemeFromNextcloudTheme(
darkTheme: getThemeFromNextcloudTheme( nextcloudTheme,
nextcloudTheme, Brightness.light,
Brightness.dark, keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false), ),
oledAsDark: themeOLEDAsDark, darkTheme: getThemeFromNextcloudTheme(
), nextcloudTheme,
routerDelegate: _routerDelegate, Brightness.dark,
), keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
oledAsDark: themeOLEDAsDark,
),
routerDelegate: _routerDelegate,
);
},
); );
}, },
), ),

4
packages/neon/neon/lib/src/blocs/accounts.dart

@ -164,9 +164,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
CapabilitiesBloc getCapabilitiesBloc(final Account account) { CapabilitiesBloc getCapabilitiesBloc(final Account account) {
if (_capabilitiesBlocs[account.id] != null) { if (_capabilitiesBlocs[account.id] != null) {
final bloc = _capabilitiesBlocs[account.id]!; return _capabilitiesBlocs[account.id]!;
unawaited(bloc.refresh());
return bloc;
} }
return _capabilitiesBlocs[account.id] = CapabilitiesBloc( return _capabilitiesBlocs[account.id] = CapabilitiesBloc(

4
packages/neon/neon/lib/src/blocs/capabilities.dart

@ -14,10 +14,6 @@ class CapabilitiesBloc extends InteractiveBloc implements CapabilitiesBlocEvents
this._requestManager, this._requestManager,
this._client, this._client,
) { ) {
capabilities.listen((final value) {
themeNotifier.value = value.data?.capabilities.theming;
});
unawaited(refresh()); unawaited(refresh());
} }

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

@ -1,7 +1,5 @@
part of '../../neon.dart'; part of '../../neon.dart';
final themeNotifier = ValueNotifier<NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming?>(null);
const themePrimaryColor = Color(0xFFF37736); const themePrimaryColor = Color(0xFFF37736);
ThemeData getThemeFromNextcloudTheme( ThemeData getThemeFromNextcloudTheme(

2
packages/neon/neon/lib/src/widgets/result_builder.dart

@ -7,7 +7,7 @@ class ResultBuilder<R> extends StatelessWidget {
super.key, super.key,
}); });
final BehaviorSubject<Result<R>> stream; final BehaviorSubject<Result<R>>? stream;
final Widget Function(BuildContext, Result<R>) builder; final Widget Function(BuildContext, Result<R>) builder;

Loading…
Cancel
Save