updateTheme method
void
updateTheme()
Updates the theme of the current window.
Implementation
void updateTheme() {
const keyPath =
r'Software\Microsoft\Windows\CurrentVersion\Themes\Personalize';
final key = Registry.openPath(RegistryHive.currentUser, path: keyPath);
// A value of 0 indicates apps should use dark mode. A non-zero or missing
// value indicates apps should use light mode.
final appsUseLightMode = key.getValueAsInt('AppsUseLightTheme');
if (appsUseLightMode != null) {
final enableDarkMode = appsUseLightMode == FALSE;
final pvAttribute = calloc<BOOL>()..value = enableDarkMode ? TRUE : FALSE;
DwmSetWindowAttribute(
hwnd,
DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE,
pvAttribute,
sizeOf<BOOL>(),
);
free(pvAttribute);
}
key.close();
}