Browse Source

fix(neon): Separate Nextcloud and device theme to fix contrast problems

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/1064/head
jld3103 1 year ago
parent
commit
f93226b2ac
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 4
      packages/app/linux/flutter/generated_plugin_registrant.cc
  2. 1
      packages/app/linux/flutter/generated_plugins.cmake
  3. 8
      packages/app/pubspec.lock
  4. 13
      packages/neon/neon/lib/src/app.dart
  5. 51
      packages/neon/neon/lib/src/theme/theme.dart
  6. 3
      packages/neon/neon/pubspec.yaml

4
packages/app/linux/flutter/generated_plugin_registrant.cc

@ -6,6 +6,7 @@
#include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <tray_manager/tray_manager_plugin.h>
@ -13,6 +14,9 @@
#include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);

1
packages/app/linux/flutter/generated_plugins.cmake

@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
file_selector_linux
screen_retriever
tray_manager

8
packages/app/pubspec.lock

@ -201,6 +201,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.2.3"
dynamic_color:
dependency: transitive
description:
name: dynamic_color
sha256: "8b8bd1d798bd393e11eddeaa8ae95b12ff028bf7d5998fc5d003488cd5f4ce2f"
url: "https://pub.dev"
source: hosted
version: "1.6.8"
dynamite_runtime:
dependency: "direct overridden"
description:

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

@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:meta/meta.dart';
@ -284,7 +285,8 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
}
@override
Widget build(final BuildContext context) => OptionsCollectionBuilder(
Widget build(final BuildContext context) => DynamicColorBuilder(
builder: (final deviceThemeLight, final deviceThemeDark) => OptionsCollectionBuilder(
valueListenable: _globalOptions,
builder: (final context, final options, final _) => StreamBuilder<Account?>(
stream: _accountsBloc.activeAccount,
@ -296,8 +298,10 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
: null,
builder: (final context, final capabilitiesSnapshot) {
final appTheme = AppTheme(
capabilitiesSnapshot.data?.capabilities.themingPublicCapabilities?.theming,
nextcloudTheme: capabilitiesSnapshot.data?.capabilities.themingPublicCapabilities?.theming,
useNextcloudTheme: options.themeUseNextcloudTheme.value,
deviceThemeLight: deviceThemeLight,
deviceThemeDark: deviceThemeDark,
oledAsDark: options.themeOLEDAsDark.value,
appThemes: _appImplementations.map((final a) => a.theme).whereNotNull(),
neonTheme: widget.neonTheme,
@ -309,7 +313,9 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
...NeonLocalizations.localizationsDelegates,
],
supportedLocales: {
..._appImplementations.map((final app) => app.supportedLocales).expand((final element) => element),
..._appImplementations
.map((final app) => app.supportedLocales)
.expand((final element) => element),
...NeonLocalizations.supportedLocales,
},
themeMode: options.themeMode.value,
@ -321,5 +327,6 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
);
},
),
),
);
}

51
packages/neon/neon/lib/src/theme/theme.dart

@ -10,8 +10,10 @@ import 'package:nextcloud/core.dart' as core;
@immutable
class AppTheme {
/// Creates a new Neon app theme.
const AppTheme(
this.nextcloudTheme, {
const AppTheme({
required this.nextcloudTheme,
required this.deviceThemeLight,
required this.deviceThemeDark,
required this.neonTheme,
final bool useNextcloudTheme = false,
this.oledAsDark = false,
@ -24,6 +26,12 @@ class AppTheme {
/// Whether to use of the Nextcloud theme.
final bool useNextcloudTheme;
/// The light theme provided by the device.
final ColorScheme? deviceThemeLight;
/// The dark theme provided by the device.
final ColorScheme? deviceThemeDark;
/// Whether to use [NcColors.oledBackground] in the dark theme.
final bool oledAsDark;
@ -34,19 +42,39 @@ class AppTheme {
final NeonTheme neonTheme;
ColorScheme _buildColorScheme(final Brightness brightness) {
final primaryColor =
nextcloudTheme?.color != null ? HexColor(nextcloudTheme!.color) : neonTheme.colorScheme.primary;
final primaryColorOverride = useNextcloudTheme ? primaryColor : null;
final oledBackgroundOverride = oledAsDark && brightness == Brightness.dark ? NcColors.oledBackground : null;
ColorScheme? colorScheme;
if (nextcloudTheme != null && useNextcloudTheme) {
final primaryColor = HexColor(nextcloudTheme!.color);
final onPrimaryColor = HexColor(nextcloudTheme!.colorText);
return ColorScheme.fromSeed(
colorScheme = ColorScheme.fromSeed(
seedColor: primaryColor,
brightness: brightness,
).copyWith(
background: oledBackgroundOverride,
primary: primaryColorOverride,
secondary: primaryColorOverride,
primary: primaryColor,
onPrimary: onPrimaryColor,
secondary: primaryColor,
onSecondary: onPrimaryColor,
tertiary: primaryColor,
onTertiary: onPrimaryColor,
);
} else {
colorScheme = brightness == Brightness.dark ? deviceThemeDark : deviceThemeLight;
}
colorScheme ??= ColorScheme.fromSeed(
seedColor: NcColors.primary,
brightness: brightness,
);
if (oledAsDark && brightness == Brightness.dark) {
colorScheme = colorScheme.copyWith(
background: NcColors.oledBackground,
);
}
return colorScheme;
}
ThemeData _getTheme(final Brightness brightness) {
@ -56,7 +84,8 @@ class AppTheme {
useMaterial3: true,
colorScheme: colorScheme,
scaffoldBackgroundColor: colorScheme.background,
cardColor: colorScheme.background, // For LicensePage
cardColor: colorScheme.background,
// For LicensePage
snackBarTheme: _snackBarTheme,
dividerTheme: _dividerTheme,
scrollbarTheme: _scrollbarTheme,

3
packages/neon/neon/pubspec.yaml

@ -9,6 +9,7 @@ environment:
dependencies:
collection: ^1.0.0
crypto: ^3.0.0
dynamic_color: ^1.0.0
file_picker: ^6.0.0
filesize: ^2.0.0
flutter:
@ -66,7 +67,7 @@ dev_dependencies:
git:
url: https://github.com/nextcloud/neon
path: packages/neon_lints
test: ^1.24.9
test: ^1.24.3
vector_graphics_compiler: ^1.1.9
flutter:

Loading…
Cancel
Save