Browse Source

neon: cleanup theming

let the MaterialApp decide wich theme to use for a given brightness
Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/311/head
Nikolas Rimikis 2 years ago
parent
commit
8d82c93457
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 71
      packages/neon/neon/lib/src/app.dart
  2. 30
      packages/neon/neon/lib/src/utils/theme.dart

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

@ -36,16 +36,8 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
); );
NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? _nextcloudTheme; NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? _nextcloudTheme;
final _platformBrightness = BehaviorSubject<Brightness>.seeded(WidgetsBinding.instance.window.platformBrightness);
Rect? _lastBounds; Rect? _lastBounds;
@override
void didChangePlatformBrightness() {
_platformBrightness.add(WidgetsBinding.instance.window.platformBrightness);
super.didChangePlatformBrightness();
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -260,42 +252,43 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
if (_platform.canUseWindowManager) { if (_platform.canUseWindowManager) {
windowManager.removeListener(this); windowManager.removeListener(this);
} }
unawaited(_platformBrightness.close());
super.dispose(); super.dispose();
} }
@override @override
Widget build(final BuildContext context) => StreamBuilder<Brightness>( Widget build(final BuildContext context) => OptionBuilder(
stream: _platformBrightness, option: widget.globalOptions.themeMode,
builder: (final context, final platformBrightnessSnapshot) => OptionBuilder( builder: (final context, final themeMode) => OptionBuilder(
option: widget.globalOptions.themeMode, option: widget.globalOptions.themeOLEDAsDark,
builder: (final context, final themeMode) => OptionBuilder( builder: (final context, final themeOLEDAsDark) => OptionBuilder(
option: widget.globalOptions.themeOLEDAsDark, option: widget.globalOptions.themeKeepOriginalAccentColor,
builder: (final context, final themeOLEDAsDark) => OptionBuilder( builder: (final context, final themeKeepOriginalAccentColor) => StreamBuilder<Account?>(
option: widget.globalOptions.themeKeepOriginalAccentColor, stream: widget.accountsBloc.activeAccount,
builder: (final context, final themeKeepOriginalAccentColor) => StreamBuilder<Account?>( builder: (final context, final activeAccountSnapshot) {
stream: widget.accountsBloc.activeAccount, if (themeMode == null || themeOLEDAsDark == null) {
builder: (final context, final activeAccountSnapshot) { return Container();
if (themeMode == null || !platformBrightnessSnapshot.hasData || themeOLEDAsDark == null) { }
return Container();
} FlutterNativeSplash.remove();
return MaterialApp.router(
FlutterNativeSplash.remove(); localizationsDelegates: AppLocalizations.localizationsDelegates,
return MaterialApp.router( supportedLocales: AppLocalizations.supportedLocales,
localizationsDelegates: AppLocalizations.localizationsDelegates, themeMode: themeMode,
supportedLocales: AppLocalizations.supportedLocales, theme: getThemeFromNextcloudTheme(
theme: getThemeFromNextcloudTheme( _nextcloudTheme,
_nextcloudTheme, Brightness.light,
themeMode, keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
platformBrightnessSnapshot.data!, ),
oledAsDark: themeOLEDAsDark, darkTheme: getThemeFromNextcloudTheme(
keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false), _nextcloudTheme,
), Brightness.dark,
routerDelegate: _routerDelegate, oledAsDark: themeOLEDAsDark,
); keepOriginalAccentColor: _nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
}, ),
), routerDelegate: _routerDelegate,
);
},
), ),
), ),
), ),

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

@ -4,31 +4,21 @@ const themePrimaryColor = Color(0xFFF37736);
ThemeData getThemeFromNextcloudTheme( ThemeData getThemeFromNextcloudTheme(
final NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? nextcloudTheme, final NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? nextcloudTheme,
final ThemeMode themeMode, final Brightness brightness, {
final Brightness platformBrightness, {
required final bool oledAsDark,
required final bool keepOriginalAccentColor, required final bool keepOriginalAccentColor,
final bool oledAsDark = false,
}) { }) {
final primaryColor = nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color!) : themePrimaryColor; if (oledAsDark) {
assert(brightness == Brightness.dark, 'Brightness.dark is required for oledAsDark.');
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;
} }
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 keepOriginalAccentColorOverride = keepOriginalAccentColor ? primaryColor : null;
final colorScheme = ColorScheme.fromSeed( final colorScheme = ColorScheme.fromSeed(
seedColor: primaryColor, seedColor: primaryColor,
brightness: selectBrightness, brightness: brightness,
).copyWith( ).copyWith(
background: oledBackgroundOverride, background: oledBackgroundOverride,
primary: keepOriginalAccentColorOverride, primary: keepOriginalAccentColorOverride,
@ -37,7 +27,7 @@ ThemeData getThemeFromNextcloudTheme(
final fillColor = MaterialStateProperty.resolveWith((final states) { final fillColor = MaterialStateProperty.resolveWith((final states) {
if (states.contains(MaterialState.disabled)) { if (states.contains(MaterialState.disabled)) {
return selectBrightness == Brightness.dark ? Colors.white38 : Colors.black38; return brightness == Brightness.dark ? Colors.white38 : Colors.black38;
} }
return colorScheme.primary; return colorScheme.primary;
@ -62,7 +52,7 @@ ThemeData getThemeFromNextcloudTheme(
), ),
popupMenuTheme: PopupMenuThemeData( popupMenuTheme: PopupMenuThemeData(
// TODO: Only needed until M3 popup menus are implemented // TODO: Only needed until M3 popup menus are implemented
color: selectBrightness == Brightness.dark color: brightness == Brightness.dark
? oledAsDark ? oledAsDark
? const Color(0xFF202020) ? const Color(0xFF202020)
: const Color(0xFF404040) : const Color(0xFF404040)

Loading…
Cancel
Save