mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-13 11:35:56 +00:00
follow system theme at startup and changing
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -192,6 +192,28 @@ class MyTheme {
|
||||
],
|
||||
);
|
||||
|
||||
static changeTo(bool dark) {
|
||||
Get.find<SharedPreferences>().setString("darkTheme", dark ? "Y" : "");
|
||||
Get.changeTheme(dark ? MyTheme.darkTheme : MyTheme.lightTheme);
|
||||
Get.forceAppUpdate();
|
||||
}
|
||||
|
||||
static bool _themeInitialed = false;
|
||||
|
||||
static ThemeData initialTheme({bool mainPage = false}) {
|
||||
bool dark;
|
||||
// Brightnesss is always light on windows, Flutter 3.0.5
|
||||
if (_themeInitialed || !mainPage || Platform.isWindows) {
|
||||
dark = isDarkTheme();
|
||||
} else {
|
||||
dark = WidgetsBinding.instance.platformDispatcher.platformBrightness ==
|
||||
Brightness.dark;
|
||||
Get.find<SharedPreferences>().setString("darkTheme", dark ? "Y" : "");
|
||||
}
|
||||
_themeInitialed = true;
|
||||
return dark ? MyTheme.darkTheme : MyTheme.lightTheme;
|
||||
}
|
||||
|
||||
static ColorThemeExtension color(BuildContext context) {
|
||||
return Theme.of(context).extension<ColorThemeExtension>()!;
|
||||
}
|
||||
@@ -201,6 +223,14 @@ class MyTheme {
|
||||
}
|
||||
}
|
||||
|
||||
class ThemeModeNotifier {
|
||||
final ValueNotifier<Brightness> brightness;
|
||||
ThemeModeNotifier(this.brightness);
|
||||
changeThemeBrightness({required Brightness brightness}) {
|
||||
this.brightness.value = brightness;
|
||||
}
|
||||
}
|
||||
|
||||
bool isDarkTheme() {
|
||||
final isDark = "Y" == Get.find<SharedPreferences>().getString("darkTheme");
|
||||
return isDark;
|
||||
|
||||
Reference in New Issue
Block a user