From 028b6801df1e98a35ad8a67118d5ec1f13e53ae7 Mon Sep 17 00:00:00 2001 From: Bruno D'Luka Date: Sun, 2 Jul 2023 21:31:41 -0300 Subject: [PATCH 1/2] Remove dark mode --- README.md | 8 -------- .../com/bruno/system_theme/SystemThemePlugin.kt | 13 ------------- lib/system_theme.dart | 10 ---------- linux/system_theme_plugin.cc | 11 ----------- macos/Classes/SystemThemePlugin.swift | 3 --- system_theme_web/lib/system_theme_web.dart | 2 -- test/system_theme_test.dart | 7 ------- windows/system_theme_plugin.cpp | 7 +------ 8 files changed, 1 insertion(+), 60 deletions(-) diff --git a/README.md b/README.md index b36237a..a6cb4f9 100644 --- a/README.md +++ b/README.md @@ -82,14 +82,6 @@ void main() async { } ``` -### Check dark mode - -Use the getter `SystemTheme.isDarkMode` to check if the device is in dark mode. - -```dart -final darkMode = SystemTheme.darkMode; -``` - ## Contribution Feel free to [open an issue](https://github.com/bdlukaa/system_theme/issues/new) if you find an error or [make pull requests](https://github.com/bdlukaa/system_theme/pulls). diff --git a/android/src/main/kotlin/com/bruno/system_theme/SystemThemePlugin.kt b/android/src/main/kotlin/com/bruno/system_theme/SystemThemePlugin.kt index 256d766..0b8f58d 100644 --- a/android/src/main/kotlin/com/bruno/system_theme/SystemThemePlugin.kt +++ b/android/src/main/kotlin/com/bruno/system_theme/SystemThemePlugin.kt @@ -25,19 +25,6 @@ class SystemThemePlugin: FlutterPlugin, ActivityAware, MethodCallHandler { override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: MethodChannel.Result) { when (call.method) { - "SystemTheme.darkMode" -> { - when (activity.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)) { - Configuration.UI_MODE_NIGHT_YES -> { - result.success(true) - } - Configuration.UI_MODE_NIGHT_NO -> { - result.success(false) - } - Configuration.UI_MODE_NIGHT_UNDEFINED -> { - result.success(false) - } - } - } "SystemTheme.accentColor" -> { val accentColor = getDeviceAccentColor(activity) val hexColor = java.lang.String.format("#%06X", 0xFFFFFF and accentColor) diff --git a/lib/system_theme.dart b/lib/system_theme.dart index 8ef49ea..a23edf3 100644 --- a/lib/system_theme.dart +++ b/lib/system_theme.dart @@ -5,7 +5,6 @@ import 'package:flutter/widgets.dart' show WidgetsFlutterBinding; /// Default system accent color. const kDefaultFallbackColor = Color(0xff00b7c3); -const kGetDarkModeMethod = 'SystemTheme.darkMode'; const kGetSystemAccentColorMethod = 'SystemTheme.accentColor'; /// Platform channel handler for invoking native methods. @@ -13,8 +12,6 @@ const MethodChannel _channel = MethodChannel('system_theme'); /// Class to return current system theme state on Windows. /// -/// [isDarkMode] returns whether currently dark mode is enabled or not. -/// /// [accentColor] returns the current accent color as a [SystemAccentColor]. To /// configure a fallback color if [accentColor] is not available, set [fallback] /// to the desired color @@ -32,13 +29,6 @@ class SystemTheme { /// It returns [kDefaultFallbackColor] for unsupported platforms static final SystemAccentColor accentColor = SystemAccentColor(fallbackColor) ..load(); - - /// Wheter the dark mode is enabled or not. Defaults to `false` - /// - /// It returns `false` for unsupported platforms - static bool get isDarkMode { - return PlatformDispatcher.instance.platformBrightness == Brightness.dark; - } } /// Defines accent colors & its variants. diff --git a/linux/system_theme_plugin.cc b/linux/system_theme_plugin.cc index 988fddd..d3be0fd 100644 --- a/linux/system_theme_plugin.cc +++ b/linux/system_theme_plugin.cc @@ -52,17 +52,6 @@ static void system_theme_plugin_handle_method_call( response = FL_METHOD_RESPONSE(fl_method_success_response_new(colors)); - } else if (strcmp(method, "SystemTheme.darkMode") == 0) { - gboolean darkMode = false; - - g_object_get(gtk_settings_get_default(), - "gtk-application-prefer-dark-theme", - &darkMode, - NULL); - - g_autoptr(FlValue) result = fl_value_new_bool(darkMode); - response = FL_METHOD_RESPONSE(fl_method_success_response_new(result)); - } else { response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new()); } diff --git a/macos/Classes/SystemThemePlugin.swift b/macos/Classes/SystemThemePlugin.swift index e3afe2b..db56e37 100644 --- a/macos/Classes/SystemThemePlugin.swift +++ b/macos/Classes/SystemThemePlugin.swift @@ -10,9 +10,6 @@ public class SystemThemePlugin: NSObject, FlutterPlugin { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { switch call.method { - case "SystemTheme.darkMode": - let type = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") ?? "Light" - result(type == "Dark"); case "SystemTheme.accentColor": if #available(macOS 10.14, *) { if let color = NSColor.controlAccentColor.usingColorSpace(.sRGB) { diff --git a/system_theme_web/lib/system_theme_web.dart b/system_theme_web/lib/system_theme_web.dart index 4949a14..20fe909 100644 --- a/system_theme_web/lib/system_theme_web.dart +++ b/system_theme_web/lib/system_theme_web.dart @@ -22,8 +22,6 @@ class SystemThemeWeb { /// https://flutter.dev/go/federated-plugins Future handleMethodCall(MethodCall call) async { switch (call.method) { - case 'SystemTheme.darkMode': - return html.window.matchMedia('(prefers-color-scheme: dark)').matches; case 'SystemTheme.accentColor': final e = html.document.body; final currentBackgroundColor = e?.style.backgroundColor; diff --git a/test/system_theme_test.dart b/test/system_theme_test.dart index b0baf11..b37ef59 100644 --- a/test/system_theme_test.dart +++ b/test/system_theme_test.dart @@ -13,8 +13,6 @@ void main() { switch (methodCall.method) { case kGetSystemAccentColorMethod: return kDefaultFallbackColor.toString(); - case kGetDarkModeMethod: - return false; default: return null; } @@ -26,11 +24,6 @@ void main() { expect(kDefaultFallbackColor.toString(), color); }); - test('Check dark mode', () async { - final darkMode = await channel.invokeMethod(kGetDarkModeMethod); - expect(false, darkMode); - }); - tearDown(() { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(channel, null); diff --git a/windows/system_theme_plugin.cpp b/windows/system_theme_plugin.cpp index 0d5c60a..fa0478d 100644 --- a/windows/system_theme_plugin.cpp +++ b/windows/system_theme_plugin.cpp @@ -61,12 +61,7 @@ namespace { SystemThemePlugin::~SystemThemePlugin() {} void SystemThemePlugin::HandleMethodCall(const flutter::MethodCall &method_call, std::unique_ptr> result) { - if (method_call.method_name() == "SystemTheme.darkMode") { - bool darkMode = false; - windows10colors::GetAppDarkModeEnabled(darkMode); - result->Success(flutter::EncodableValue(darkMode)); - } - else if (method_call.method_name() == "SystemTheme.accentColor") { + if (method_call.method_name() == "SystemTheme.accentColor") { windows10colors::AccentColor accentColors; windows10colors::GetAccentColor(accentColors); flutter::EncodableMap colors = flutter::EncodableMap(); From 5f26f5b33a0ac845da961c0d0c92bba9a6884936 Mon Sep 17 00:00:00 2001 From: Bruno D'Luka Date: Sun, 2 Jul 2023 21:35:15 -0300 Subject: [PATCH 2/2] Remove unused import --- lib/system_theme.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/system_theme.dart b/lib/system_theme.dart index a23edf3..0fc9a92 100644 --- a/lib/system_theme.dart +++ b/lib/system_theme.dart @@ -1,5 +1,4 @@ -import 'package:flutter/foundation.dart' show PlatformDispatcher; -import 'package:flutter/services.dart' show MethodChannel, Brightness, Color; +import 'package:flutter/services.dart' show MethodChannel, Color; import 'package:flutter/widgets.dart' show WidgetsFlutterBinding; /// Default system accent color.