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..0fc9a92 100644 --- a/lib/system_theme.dart +++ b/lib/system_theme.dart @@ -1,11 +1,9 @@ -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. const kDefaultFallbackColor = Color(0xff00b7c3); -const kGetDarkModeMethod = 'SystemTheme.darkMode'; const kGetSystemAccentColorMethod = 'SystemTheme.accentColor'; /// Platform channel handler for invoking native methods. @@ -13,8 +11,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 +28,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();