Reputation: 7659
I'm trying to change theme dynamically using GetX library., it works perfectly on iOS simulator, but it does not work on real device.
I'm using this code:
Get.changeTheme(AppThemes.darkTheme);
darkTheme is the custom theme I want to switch to.
Upvotes: 1
Views: 1612
Reputation: 29
Get.changeTheme
requires a daily !
Get.changeTheme(currentThemeData);
await Future<void>.delayed(const Duration(milliseconds: 500));
await Get.forceAppUpdate();
Upvotes: 0
Reputation: 1
I came across this page because I ran into the exact same problem.
Fortunately, I was able to find a solution: It seems, on a real device, after calling Get.changeTheme()
, you need to call Get.forceAppUpdate()
to make it count.
Example:
Get.changeTheme(buildTheme(value ? Brightness.dark : Brightness.light));
await Get.forceAppUpdate();
Upvotes: 0
Reputation: 31
I resolved GetX dynamic change theme issue by referencing ThemeMode as per code below instead of the GetX code sample using ThemeData.
In my case this fixed issue where the default device system dark mode would not dynamically update to my ThemeData.light mode.
//Get.changeTheme(Get.isDarkMode ? ThemeData.light() : ThemeData.dark()); //Code from GetX change theme documentation did not work
Get.changeThemeMode(Get.isDarkMode ? ThemeMode.light : ThemeMode.dark); //Modified successfully by referencing ThemeMode
setState(() {
});
Upvotes: 3