Skip to content

Conversation

@axoroll7
Copy link

Issue

If the preferred system theme is lightMode, it is impossible to switch to darkMode, on Windows.

await windowManager.setBrightness(Brightness.light); await windowManager.setBrightness(Brightness.dark);

Solution

The preferred theme should not be taken into account, like the MacOS implementation.
In the swift file for MacOS, the theme is simply updated by passing an argument :

public func setBrightness(_ args: [String: Any]) { let brightness: String = args["brightness"] as! String if (brightness == "dark") { mainWindow.appearance = NSAppearance(named: NSAppearance.Name.vibrantDark) } else { mainWindow.appearance = NSAppearance(named: NSAppearance.Name.vibrantLight) } mainWindow.invalidateShadow() }

But in the file for Windows, the system preferred theme is retrieved, and utilized incorrectly. Instead of doing:

BOOL enable_dark_mode = light_mode == 0 && brightness == "dark";

It should be:

BOOL enable_dark_mode = brightness == "dark";

(Apologies, English isn't my first language.)

@axoroll7
Copy link
Author

My apologies, after some tests I concluded the initial method is also valid. It didn't work at first in my tests because I didn't take into account that flutter changes automatically the title bar when the MaterialApp theme changes. That's another issue. Thank you

@axoroll7 axoroll7 closed this Aug 11, 2024
@axoroll7
Copy link
Author

If anyone is wondering how I managed to work around my problem, I put a debouncing in my stream listener to let the flutter engine do its change before mine. My stream is activated on themeMode changes, or platformBrightness if themeMode is ThemeMode.system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant