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. 39
      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

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

@ -28,14 +28,8 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
late final _routerDelegate = AppRouter( late final _routerDelegate = AppRouter(
navigatorKey: _navigatorKey, navigatorKey: _navigatorKey,
accountsBloc: _accountsBloc, accountsBloc: _accountsBloc,
onThemeChanged: (final nextcloudTheme) {
setState(() {
_nextcloudTheme = nextcloudTheme;
});
},
); );
NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? _nextcloudTheme;
Rect? _lastBounds; Rect? _lastBounds;
@override @override
@ -271,22 +265,25 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
} }
FlutterNativeSplash.remove(); FlutterNativeSplash.remove();
return MaterialApp.router( return ValueListenableBuilder(
localizationsDelegates: AppLocalizations.localizationsDelegates, valueListenable: themeNotifier,
supportedLocales: AppLocalizations.supportedLocales, builder: (final context, final nextcloudTheme, final child) => MaterialApp.router(
themeMode: themeMode, localizationsDelegates: AppLocalizations.localizationsDelegates,
theme: getThemeFromNextcloudTheme( supportedLocales: AppLocalizations.supportedLocales,
_nextcloudTheme, themeMode: themeMode,
Brightness.light, theme: getThemeFromNextcloudTheme(
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false), nextcloudTheme,
), Brightness.light,
darkTheme: getThemeFromNextcloudTheme( keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
_nextcloudTheme, ),
Brightness.dark, darkTheme: getThemeFromNextcloudTheme(
oledAsDark: themeOLEDAsDark, nextcloudTheme,
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false), Brightness.dark,
keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
oledAsDark: themeOLEDAsDark,
),
routerDelegate: _routerDelegate,
), ),
routerDelegate: _routerDelegate,
); );
}, },
), ),

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

@ -14,6 +14,10 @@ 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());
} }

4
packages/neon/neon/lib/src/pages/home.dart

@ -5,12 +5,10 @@ const kQuickBarWidth = kAvatarSize + 20;
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const HomePage({ const HomePage({
required this.account, required this.account,
required this.onThemeChanged,
super.key, super.key,
}); });
final Account account; final Account account;
final Function(NextcloudTheme? theme) onThemeChanged;
@override @override
State<HomePage> createState() => _HomePageState(); State<HomePage> createState() => _HomePageState();
@ -48,8 +46,6 @@ class _HomePageState extends State<HomePage> {
_capabilitiesBloc.capabilities.listen((final result) async { _capabilitiesBloc.capabilities.listen((final result) async {
if (result.data != null) { if (result.data != null) {
widget.onThemeChanged(result.data!.capabilities.theming);
// ignore cached version and prevent duplicate dialogs // ignore cached version and prevent duplicate dialogs
if (result.cached) { if (result.cached) {
return; return;

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

@ -5,11 +5,9 @@ class AppRouter extends RouterDelegate<Account> with ChangeNotifier, PopNavigato
AppRouter({ AppRouter({
required this.navigatorKey, required this.navigatorKey,
required this.accountsBloc, required this.accountsBloc,
required this.onThemeChanged,
}); });
final AccountsBloc accountsBloc; final AccountsBloc accountsBloc;
final Function(NextcloudTheme? theme) onThemeChanged;
final _globalPopups = const GlobalPopups(); final _globalPopups = const GlobalPopups();
@override @override
@ -41,7 +39,6 @@ class AppRouter extends RouterDelegate<Account> with ChangeNotifier, PopNavigato
HomePage( HomePage(
key: Key(currentConfiguration!.id), key: Key(currentConfiguration!.id),
account: currentConfiguration!, account: currentConfiguration!,
onThemeChanged: onThemeChanged,
), ),
], ],
), ),

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

@ -1,5 +1,7 @@
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(

Loading…
Cancel
Save