Browse Source

neon: cleanup changing of NextcloudTheme

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/311/head
Nikolas Rimikis 2 years ago
parent
commit
1e7ce247c9
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 19
      packages/neon/neon/lib/src/app.dart
  2. 4
      packages/neon/neon/lib/src/blocs/capabilities.dart
  3. 4
      packages/neon/neon/lib/src/pages/home.dart
  4. 3
      packages/neon/neon/lib/src/router.dart
  5. 2
      packages/neon/neon/lib/src/utils/theme.dart

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

@ -28,14 +28,8 @@ class _NeonAppState extends State<NeonApp> 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<NeonApp> with WidgetsBindingObserver, tray.Tra
}
FlutterNativeSplash.remove();
return MaterialApp.router(
return ValueListenableBuilder(
valueListenable: themeNotifier,
builder: (final context, final nextcloudTheme, final child) => MaterialApp.router(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
themeMode: themeMode,
theme: getThemeFromNextcloudTheme(
_nextcloudTheme,
nextcloudTheme,
Brightness.light,
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
),
darkTheme: getThemeFromNextcloudTheme(
_nextcloudTheme,
nextcloudTheme,
Brightness.dark,
keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
oledAsDark: themeOLEDAsDark,
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
),
routerDelegate: _routerDelegate,
),
);
},
),

4
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());
}

4
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<HomePage> createState() => _HomePageState();
@ -48,8 +46,6 @@ class _HomePageState extends State<HomePage> {
_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;

3
packages/neon/neon/lib/src/router.dart

@ -5,11 +5,9 @@ class AppRouter extends RouterDelegate<Account> 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<Account> with ChangeNotifier, PopNavigato
HomePage(
key: Key(currentConfiguration!.id),
account: currentConfiguration!,
onThemeChanged: onThemeChanged,
),
],
),

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

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

Loading…
Cancel
Save