Browse Source

Merge pull request #311 from Leptopoda/cleanup/theming

neon: cleanup theming
pull/310/head
Kate 2 years ago committed by GitHub
parent
commit
f22240a321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      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. 32
      packages/neon/neon/lib/src/utils/theme.dart

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

@ -28,24 +28,10 @@ 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;
final _platformBrightness = BehaviorSubject<Brightness>.seeded(WidgetsBinding.instance.window.platformBrightness);
Rect? _lastBounds;
@override
void didChangePlatformBrightness() {
_platformBrightness.add(WidgetsBinding.instance.window.platformBrightness);
super.didChangePlatformBrightness();
}
@override
void initState() {
super.initState();
@ -260,15 +246,12 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
if (_platform.canUseWindowManager) {
windowManager.removeListener(this);
}
unawaited(_platformBrightness.close());
super.dispose();
}
@override
Widget build(final BuildContext context) => StreamBuilder<Brightness>(
stream: _platformBrightness,
builder: (final context, final platformBrightnessSnapshot) => OptionBuilder(
Widget build(final BuildContext context) => OptionBuilder(
option: widget.globalOptions.themeMode,
builder: (final context, final themeMode) => OptionBuilder(
option: widget.globalOptions.themeOLEDAsDark,
@ -277,27 +260,34 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
builder: (final context, final themeKeepOriginalAccentColor) => StreamBuilder<Account?>(
stream: widget.accountsBloc.activeAccount,
builder: (final context, final activeAccountSnapshot) {
if (themeMode == null || !platformBrightnessSnapshot.hasData || themeOLEDAsDark == null) {
if (themeMode == null || themeOLEDAsDark == null) {
return Container();
}
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,
themeMode,
platformBrightnessSnapshot.data!,
nextcloudTheme,
Brightness.light,
keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
),
darkTheme: getThemeFromNextcloudTheme(
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,
),
],
),

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

@ -1,34 +1,26 @@
part of '../../neon.dart';
final themeNotifier = ValueNotifier<NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming?>(null);
const themePrimaryColor = Color(0xFFF37736);
ThemeData getThemeFromNextcloudTheme(
final NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? nextcloudTheme,
final ThemeMode themeMode,
final Brightness platformBrightness, {
required final bool oledAsDark,
final Brightness brightness, {
required final bool keepOriginalAccentColor,
final bool oledAsDark = false,
}) {
final primaryColor = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color!) : themePrimaryColor;
late final Brightness selectBrightness;
switch (themeMode) {
case ThemeMode.system:
selectBrightness = platformBrightness;
break;
case ThemeMode.light:
selectBrightness = Brightness.light;
break;
case ThemeMode.dark:
selectBrightness = Brightness.dark;
break;
if (oledAsDark) {
assert(brightness == Brightness.dark, 'Brightness.dark is required for oledAsDark.');
}
final oledBackgroundOverride = selectBrightness == Brightness.dark && oledAsDark ? Colors.black : null;
final primaryColor = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color!) : themePrimaryColor;
final oledBackgroundOverride = oledAsDark ? Colors.black : null;
final keepOriginalAccentColorOverride = keepOriginalAccentColor ? primaryColor : null;
final colorScheme = ColorScheme.fromSeed(
seedColor: primaryColor,
brightness: selectBrightness,
brightness: brightness,
).copyWith(
background: oledBackgroundOverride,
primary: keepOriginalAccentColorOverride,
@ -37,7 +29,7 @@ ThemeData getThemeFromNextcloudTheme(
final fillColor = MaterialStateProperty.resolveWith((final states) {
if (states.contains(MaterialState.disabled)) {
return selectBrightness == Brightness.dark ? Colors.white38 : Colors.black38;
return brightness == Brightness.dark ? Colors.white38 : Colors.black38;
}
return colorScheme.primary;
@ -62,7 +54,7 @@ ThemeData getThemeFromNextcloudTheme(
),
popupMenuTheme: PopupMenuThemeData(
// TODO: Only needed until M3 popup menus are implemented
color: selectBrightness == Brightness.dark
color: brightness == Brightness.dark
? oledAsDark
? const Color(0xFF202020)
: const Color(0xFF404040)

Loading…
Cancel
Save