Skip to content

Commit

Permalink
Remove dark mode (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Jul 3, 2023
2 parents c996642 + 5f26f5b commit 72d5da0
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 62 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 1 addition & 12 deletions lib/system_theme.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
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.
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
Expand All @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions linux/system_theme_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
3 changes: 0 additions & 3 deletions macos/Classes/SystemThemePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions system_theme_web/lib/system_theme_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class SystemThemeWeb {
/// https://flutter.dev/go/federated-plugins
Future<dynamic> 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;
Expand Down
7 changes: 0 additions & 7 deletions test/system_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ void main() {
switch (methodCall.method) {
case kGetSystemAccentColorMethod:
return kDefaultFallbackColor.toString();
case kGetDarkModeMethod:
return false;
default:
return null;
}
Expand All @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions windows/system_theme_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ namespace {
SystemThemePlugin::~SystemThemePlugin() {}

void SystemThemePlugin::HandleMethodCall(const flutter::MethodCall<flutter::EncodableValue> &method_call, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> 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();
Expand Down

0 comments on commit 72d5da0

Please sign in to comment.