refactor: Use dynamic color package instead of system theme

This commit is contained in:
Christian Pauly 2023-02-03 09:27:25 +01:00
parent 0f69a1fefb
commit 13a3321bab
8 changed files with 12 additions and 54 deletions

View File

@ -1,12 +1,9 @@
import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:system_theme/system_theme.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/platform_infos.dart';
class ThemeBuilder extends StatefulWidget {
final Widget Function(
@ -89,28 +86,16 @@ class ThemeController extends State<ThemeBuilder> {
super.initState();
}
Color get systemAccentColor {
if (PlatformInfos.isLinux) return AppConfig.chatColor;
try {
// a bad plugin implementation
// https://github.com/bdlukaa/system_theme/issues/10
final accentColor = SystemTheme.accentColor;
final color = accentColor.accent;
return color;
} catch (_) {
return AppConfig.chatColor;
}
}
@override
Widget build(BuildContext context) {
return Provider(
create: (_) => this,
child: widget.builder(
context,
themeMode,
primaryColor ?? systemAccentColor,
),
child: DynamicColorBuilder(
builder: (light, _) => widget.builder(
context,
themeMode,
primaryColor ?? light?.primary,
)),
);
}
}

View File

@ -14,7 +14,6 @@
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <handy_window/handy_window_plugin.h>
#include <record_linux/record_linux_plugin.h>
#include <system_theme/system_theme_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
@ -42,9 +41,6 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) record_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "RecordLinuxPlugin");
record_linux_plugin_register_with_registrar(record_linux_registrar);
g_autoptr(FlPluginRegistrar) system_theme_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SystemThemePlugin");
system_theme_plugin_register_with_registrar(system_theme_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

View File

@ -11,7 +11,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux
handy_window
record_linux
system_theme
url_launcher_linux
)

View File

@ -27,7 +27,6 @@ import record_macos
import share_plus_macos
import shared_preferences_macos
import sqflite
import system_theme
import url_launcher_macos
import video_compress
import wakelock_macos
@ -55,7 +54,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
SystemThemePlugin.register(with: registry.registrar(forPlugin: "SystemThemePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
VideoCompressPlugin.register(with: registry.registrar(forPlugin: "VideoCompressPlugin"))
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))

View File

@ -346,13 +346,13 @@ packages:
source: hosted
version: "0.2.1"
dynamic_color:
dependency: transitive
dependency: "direct main"
description:
name: dynamic_color
sha256: "37a15576f5a0bfd5555b613cf20ea3bd379607cf88d457374a16032f4e942174"
sha256: "0ff251e8a31f54adde9ab4d4b301c94df46dcd34e4fbd6d7623631ed174b205e"
url: "https://pub.dev"
source: hosted
version: "1.5.4"
version: "1.6.0"
emoji_picker_flutter:
dependency: "direct main"
description:
@ -1852,22 +1852,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.1"
system_theme:
dependency: "direct main"
description:
name: system_theme
sha256: "28bb63b997c252eee7fea6dc9e3528a9a6bf4b566ccbc8b49926389ca3e2c96b"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
system_theme_web:
dependency: transitive
description:
name: system_theme_web
sha256: "7566f5a928f6d28d7a60c97bea8a851d1c6bc9b86a4df2366230a97458489219"
url: "https://pub.dev"
source: hosted
version: "0.0.2"
term_glyph:
dependency: transitive
description:
@ -2286,4 +2270,4 @@ packages:
version: "3.1.1"
sdks:
dart: ">=2.19.0 <4.0.0"
flutter: ">=3.3.0"
flutter: ">=3.4.0-17.0.pre"

View File

@ -20,6 +20,7 @@ dependencies:
desktop_lifecycle: ^0.1.0
desktop_notifications: ^0.6.3
device_info_plus: ^8.0.0
dynamic_color: ^1.6.0
emoji_picker_flutter: ^1.5.1
emoji_proposal: ^0.0.1
emojis: ^0.9.9
@ -77,7 +78,6 @@ dependencies:
shared_preferences: 2.0.15 # Pinned because https://github.com/flutter/flutter/issues/118401
slugify: ^2.0.0
swipe_to_action: ^0.2.0
system_theme: ^2.0.0
tor_detector_web: ^1.1.0
uni_links: ^0.5.1
unifiedpush: ^4.0.3

View File

@ -15,7 +15,6 @@
#include <flutter_webrtc/flutter_web_r_t_c_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <record_windows/record_windows_plugin_c_api.h>
#include <system_theme/system_theme_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
@ -37,8 +36,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
RecordWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("RecordWindowsPluginCApi"));
SystemThemePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SystemThemePlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}

View File

@ -12,7 +12,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
flutter_webrtc
permission_handler_windows
record_windows
system_theme
url_launcher_windows
)