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();
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<Capabilities?>(
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,
);
},
);
},
),

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) {
if (_capabilitiesBlocs[account.id] != null) {
final bloc = _capabilitiesBlocs[account.id]!;
unawaited(bloc.refresh());
return bloc;
return _capabilitiesBlocs[account.id]!;
}
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._client,
) {
capabilities.listen((final value) {
themeNotifier.value = value.data?.capabilities.theming;
});
unawaited(refresh());
}

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

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

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

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

Loading…
Cancel
Save