Browse Source

neon: Fix theme switching

pull/320/head
jld3103 2 years ago
parent
commit
00c1411b9d
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 13
      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

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

@ -265,9 +265,13 @@ 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
: null,
builder: (final context, final capabilitiesSnapshot) {
final nextcloudTheme = capabilitiesSnapshot.data?.capabilities.theming;
return MaterialApp.router(
localizationsDelegates: AppLocalizations.localizationsDelegates, localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales, supportedLocales: AppLocalizations.supportedLocales,
themeMode: themeMode, themeMode: themeMode,
@ -283,7 +287,8 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
oledAsDark: themeOLEDAsDark, oledAsDark: themeOLEDAsDark,
), ),
routerDelegate: _routerDelegate, 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