refactor(theming): Remove gtk and win plugins for color extraction
Default plugin now takes care of thatpull/158/head
parent
e342727181
commit
fc3d78662e
|
@ -1,10 +1,7 @@
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:dynamic_color/dynamic_color.dart';
|
import 'package:dynamic_color/dynamic_color.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:system_theme/system_theme.dart';
|
import 'package:material_color_utilities/palettes/core_palette.dart';
|
||||||
import 'package:gtk_theme_fl/gtk_theme_fl.dart';
|
|
||||||
|
|
||||||
abstract class AppThemeFactory {
|
abstract class AppThemeFactory {
|
||||||
AppThemeFactory._();
|
AppThemeFactory._();
|
||||||
|
@ -22,40 +19,18 @@ abstract class AppThemeFactory {
|
||||||
required final Color fallbackColor,
|
required final Color fallbackColor,
|
||||||
final bool isDark = false,
|
final bool isDark = false,
|
||||||
}) async {
|
}) async {
|
||||||
ColorScheme? gtkColorsScheme;
|
|
||||||
final Brightness brightness = isDark ? Brightness.dark : Brightness.light;
|
final Brightness brightness = isDark ? Brightness.dark : Brightness.light;
|
||||||
|
|
||||||
final ColorScheme? dynamicColorsScheme =
|
final ColorScheme? dynamicColorsScheme =
|
||||||
await _getDynamicColors(brightness);
|
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(
|
final ColorScheme fallbackColorScheme = ColorScheme.fromSeed(
|
||||||
seedColor: accentColor.accent,
|
seedColor: fallbackColor,
|
||||||
brightness: brightness,
|
brightness: brightness,
|
||||||
);
|
);
|
||||||
|
|
||||||
final ColorScheme colorScheme =
|
final ColorScheme colorScheme =
|
||||||
dynamicColorsScheme ?? gtkColorsScheme ?? fallbackColorScheme;
|
dynamicColorsScheme ?? fallbackColorScheme;
|
||||||
|
|
||||||
final Typography appTypography = Typography.material2021();
|
final Typography appTypography = Typography.material2021();
|
||||||
|
|
||||||
|
@ -80,4 +55,12 @@ abstract class AppThemeFactory {
|
||||||
return Future.value(null);
|
return Future.value(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<CorePalette?> getCorePalette() async {
|
||||||
|
try {
|
||||||
|
return await DynamicColorPlugin.getCorePalette();
|
||||||
|
} on PlatformException {
|
||||||
|
return Future.value(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,17 @@
|
||||||
|
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
|
#include <dynamic_color/dynamic_color_plugin.h>
|
||||||
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
|
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
|
||||||
#include <gtk_theme_fl/gtk_theme_fl_plugin.h>
|
|
||||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||||
|
|
||||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
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 =
|
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
|
||||||
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
|
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 =
|
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
||||||
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
|
dynamic_color
|
||||||
flutter_secure_storage_linux
|
flutter_secure_storage_linux
|
||||||
gtk_theme_fl
|
|
||||||
url_launcher_linux
|
url_launcher_linux
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
27
pubspec.lock
27
pubspec.lock
|
@ -308,7 +308,7 @@ packages:
|
||||||
name: dynamic_color
|
name: dynamic_color
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.0"
|
version: "1.5.4"
|
||||||
easy_localization:
|
easy_localization:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -602,13 +602,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
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:
|
hive:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -764,7 +757,7 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.12"
|
version: "0.12.12"
|
||||||
material_color_utilities:
|
material_color_utilities:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: material_color_utilities
|
name: material_color_utilities
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
|
@ -1188,20 +1181,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.1"
|
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:
|
term_glyph:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -1414,4 +1393,4 @@ packages:
|
||||||
version: "3.1.1"
|
version: "3.1.1"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.17.0 <3.0.0"
|
dart: ">=2.17.0 <3.0.0"
|
||||||
flutter: ">=3.0.0"
|
flutter: ">=3.3.0"
|
||||||
|
|
|
@ -14,7 +14,7 @@ dependencies:
|
||||||
cubit_form: ^2.0.1
|
cubit_form: ^2.0.1
|
||||||
device_info_plus: ^4.0.1
|
device_info_plus: ^4.0.1
|
||||||
dio: ^4.0.4
|
dio: ^4.0.4
|
||||||
dynamic_color: ^1.4.0
|
dynamic_color: ^1.5.4
|
||||||
easy_localization: ^3.0.0
|
easy_localization: ^3.0.0
|
||||||
either_option: ^2.0.1-dev.1
|
either_option: ^2.0.1-dev.1
|
||||||
equatable: ^2.0.3
|
equatable: ^2.0.3
|
||||||
|
@ -30,7 +30,6 @@ dependencies:
|
||||||
graphql: ^5.1.1
|
graphql: ^5.1.1
|
||||||
graphql_codegen: ^0.10.2
|
graphql_codegen: ^0.10.2
|
||||||
graphql_flutter: ^5.1.0
|
graphql_flutter: ^5.1.0
|
||||||
gtk_theme_fl: ^0.0.1
|
|
||||||
hive: ^2.2.3
|
hive: ^2.2.3
|
||||||
hive_flutter: ^1.1.0
|
hive_flutter: ^1.1.0
|
||||||
http: ^0.13.5
|
http: ^0.13.5
|
||||||
|
@ -38,6 +37,7 @@ dependencies:
|
||||||
ionicons: ^0.1.2
|
ionicons: ^0.1.2
|
||||||
json_annotation: ^4.6.0
|
json_annotation: ^4.6.0
|
||||||
local_auth: ^2.0.2
|
local_auth: ^2.0.2
|
||||||
|
material_color_utilities: ^0.1.5
|
||||||
modal_bottom_sheet: ^2.0.1
|
modal_bottom_sheet: ^2.0.1
|
||||||
nanoid: ^1.0.0
|
nanoid: ^1.0.0
|
||||||
package_info: ^2.0.2
|
package_info: ^2.0.2
|
||||||
|
@ -45,7 +45,6 @@ dependencies:
|
||||||
provider: ^6.0.2
|
provider: ^6.0.2
|
||||||
pub_semver: ^2.1.1
|
pub_semver: ^2.1.1
|
||||||
share_plus: ^4.0.4
|
share_plus: ^4.0.4
|
||||||
system_theme: ^2.0.0
|
|
||||||
timezone: ^0.8.0
|
timezone: ^0.8.0
|
||||||
url_launcher: ^6.0.20
|
url_launcher: ^6.0.20
|
||||||
wakelock: ^0.6.1+1
|
wakelock: ^0.6.1+1
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
|
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
|
||||||
#include <dynamic_color/dynamic_color_plugin_c_api.h>
|
#include <dynamic_color/dynamic_color_plugin_c_api.h>
|
||||||
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
|
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
|
||||||
#include <system_theme/system_theme_plugin.h>
|
|
||||||
#include <url_launcher_windows/url_launcher_windows.h>
|
#include <url_launcher_windows/url_launcher_windows.h>
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
|
@ -19,8 +18,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
|
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
|
||||||
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
|
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
|
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
|
||||||
SystemThemePluginRegisterWithRegistrar(
|
|
||||||
registry->GetRegistrarForPlugin("SystemThemePlugin"));
|
|
||||||
UrlLauncherWindowsRegisterWithRegistrar(
|
UrlLauncherWindowsRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
connectivity_plus_windows
|
connectivity_plus_windows
|
||||||
dynamic_color
|
dynamic_color
|
||||||
flutter_secure_storage_windows
|
flutter_secure_storage_windows
|
||||||
system_theme
|
|
||||||
url_launcher_windows
|
url_launcher_windows
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue