From fc3d78662e31b5fbe75cb253fbdeb4fc4cc935f0 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Sat, 31 Dec 2022 05:33:04 +0300 Subject: [PATCH] refactor(theming): Remove gtk and win plugins for color extraction Default plugin now takes care of that --- lib/theming/factory/app_theme_factory.dart | 39 ++++++------------- linux/flutter/generated_plugin_registrant.cc | 8 ++-- linux/flutter/generated_plugins.cmake | 2 +- pubspec.lock | 27 ++----------- pubspec.yaml | 5 +-- .../flutter/generated_plugin_registrant.cc | 3 -- windows/flutter/generated_plugins.cmake | 1 - 7 files changed, 21 insertions(+), 64 deletions(-) diff --git a/lib/theming/factory/app_theme_factory.dart b/lib/theming/factory/app_theme_factory.dart index 65bb1648..2b7309d5 100644 --- a/lib/theming/factory/app_theme_factory.dart +++ b/lib/theming/factory/app_theme_factory.dart @@ -1,10 +1,7 @@ -import 'dart:io'; - import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:system_theme/system_theme.dart'; -import 'package:gtk_theme_fl/gtk_theme_fl.dart'; +import 'package:material_color_utilities/palettes/core_palette.dart'; abstract class AppThemeFactory { AppThemeFactory._(); @@ -22,40 +19,18 @@ abstract class AppThemeFactory { required final Color fallbackColor, final bool isDark = false, }) async { - ColorScheme? gtkColorsScheme; final Brightness brightness = isDark ? Brightness.dark : Brightness.light; final ColorScheme? dynamicColorsScheme = await _getDynamicColors(brightness); - if (Platform.isLinux) { - final GtkThemeData themeData = await GtkThemeData.initialize(); - final bool isGtkDark = - Color(themeData.theme_bg_color).computeLuminance() < 0.5; - final bool isInverseNeeded = isGtkDark != isDark; - gtkColorsScheme = ColorScheme.fromSeed( - seedColor: Color(themeData.theme_selected_bg_color), - brightness: brightness, - background: isInverseNeeded ? null : Color(themeData.theme_bg_color), - surface: isInverseNeeded ? null : Color(themeData.theme_base_color), - ); - } - - final SystemAccentColor accentColor = SystemAccentColor(fallbackColor); - - try { - await accentColor.load(); - } on MissingPluginException catch (e) { - print('_createAppTheme: ${e.message}'); - } - final ColorScheme fallbackColorScheme = ColorScheme.fromSeed( - seedColor: accentColor.accent, + seedColor: fallbackColor, brightness: brightness, ); final ColorScheme colorScheme = - dynamicColorsScheme ?? gtkColorsScheme ?? fallbackColorScheme; + dynamicColorsScheme ?? fallbackColorScheme; final Typography appTypography = Typography.material2021(); @@ -80,4 +55,12 @@ abstract class AppThemeFactory { return Future.value(null); } } + + static Future getCorePalette() async { + try { + return await DynamicColorPlugin.getCorePalette(); + } on PlatformException { + return Future.value(null); + } + } } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index cf327b12..075ecba3 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,17 +6,17 @@ #include "generated_plugin_registrant.h" +#include #include -#include #include 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) flutter_secure_storage_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin"); flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar); - g_autoptr(FlPluginRegistrar) gtk_theme_fl_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "GtkThemeFlPlugin"); - gtk_theme_fl_plugin_register_with_registrar(gtk_theme_fl_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); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 6c700a87..6fd458b2 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,8 +3,8 @@ # list(APPEND FLUTTER_PLUGIN_LIST + dynamic_color flutter_secure_storage_linux - gtk_theme_fl url_launcher_linux ) diff --git a/pubspec.lock b/pubspec.lock index c5901997..cb43c377 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -308,7 +308,7 @@ packages: name: dynamic_color url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.5.4" easy_localization: dependency: "direct main" description: @@ -602,13 +602,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" - gtk_theme_fl: - dependency: "direct main" - description: - name: gtk_theme_fl - url: "https://pub.dartlang.org" - source: hosted - version: "0.0.1" hive: dependency: "direct main" description: @@ -764,7 +757,7 @@ packages: source: hosted version: "0.12.12" material_color_utilities: - dependency: transitive + dependency: "direct main" description: name: material_color_utilities url: "https://pub.dartlang.org" @@ -1188,20 +1181,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.1" - system_theme: - dependency: "direct main" - description: - name: system_theme - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" - system_theme_web: - dependency: transitive - description: - name: system_theme_web - url: "https://pub.dartlang.org" - source: hosted - version: "0.0.2" term_glyph: dependency: transitive description: @@ -1414,4 +1393,4 @@ packages: version: "3.1.1" sdks: dart: ">=2.17.0 <3.0.0" - flutter: ">=3.0.0" + flutter: ">=3.3.0" diff --git a/pubspec.yaml b/pubspec.yaml index af1521e1..dc69cd58 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: cubit_form: ^2.0.1 device_info_plus: ^4.0.1 dio: ^4.0.4 - dynamic_color: ^1.4.0 + dynamic_color: ^1.5.4 easy_localization: ^3.0.0 either_option: ^2.0.1-dev.1 equatable: ^2.0.3 @@ -30,7 +30,6 @@ dependencies: graphql: ^5.1.1 graphql_codegen: ^0.10.2 graphql_flutter: ^5.1.0 - gtk_theme_fl: ^0.0.1 hive: ^2.2.3 hive_flutter: ^1.1.0 http: ^0.13.5 @@ -38,6 +37,7 @@ dependencies: ionicons: ^0.1.2 json_annotation: ^4.6.0 local_auth: ^2.0.2 + material_color_utilities: ^0.1.5 modal_bottom_sheet: ^2.0.1 nanoid: ^1.0.0 package_info: ^2.0.2 @@ -45,7 +45,6 @@ dependencies: provider: ^6.0.2 pub_semver: ^2.1.1 share_plus: ^4.0.4 - system_theme: ^2.0.0 timezone: ^0.8.0 url_launcher: ^6.0.20 wakelock: ^0.6.1+1 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 1feb1b08..9c422c29 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -9,7 +9,6 @@ #include #include #include -#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { @@ -19,8 +18,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("DynamicColorPluginCApi")); FlutterSecureStorageWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); - SystemThemePluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("SystemThemePlugin")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index fa5d72de..0039d570 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -6,7 +6,6 @@ list(APPEND FLUTTER_PLUGIN_LIST connectivity_plus_windows dynamic_color flutter_secure_storage_windows - system_theme url_launcher_windows )