0

I am having an issue with Flutter's GetX package when using the Get.changeTheme() method. The method works perfectly fine when running the app in debug mode on the Android emulator. However, after I install the release APK on a physical device or when running the desktop version of the app, the Get.changeTheme() method doesn't seem to have any effect.

This is my button:

IconButton(
  onPressed: () async {
    if (darkMode.value) {
      await localStorageController.setDarkMode(false);
      darkMode.value = false;
    } else {
      await localStorageController.setDarkMode(true);
      darkMode.value = true;
    }
    print(darkMode.value);
    if (darkMode.value) {
      Get.changeTheme(ThemeData.dark());
      print('Dark');
    } else {
      Get.changeTheme(ThemeData.light());
      print('Light');
    }
  },
  icon: const Icon(Icons.dark_mode)
),

Here is my [Flutter doctor]

Ramji
  • 904
  • 2
  • 5
  • 20
  • Experts agree to look elsewhere besides GetX. If you're on the flutter discord, type ?getx. Otherwise, this seven minute video presents a good detailed description of "why not getx": https://youtu.be/zlIgy4es5Ts – Randal Schwartz Jun 16 '23 at 19:30
  • did you try inside setState() function? Something like setState(() {darkMode.value = false;}); – Mearaj Jun 16 '23 at 23:41
  • @Mearaj there is no affect of setstate((){}) while changing theme as setstate((){}) only rebuild the current build context. And also darkMode is observable variable which i created for changing icon according to theme later on. – Abdul moiz Jun 17 '23 at 00:06
  • How are you initializing the theme in the beginning? Retrieving from the localStorageController or using default values. If you are using default values, then make sure you first try to retrieve from localStorageController and if it doesn't exist, then only apply your default values. Got the idea? – Mearaj Jun 17 '23 at 00:33
  • @Mearaj yes i am using localStorageController. the problem is every thing is working fine when running from android studio in mobile emulator as device but after i release and I install apk it is not working. Same when running from android studio and desktop as device same nothing happen and there is no error on run console. – Abdul moiz Jun 17 '23 at 02:28
  • Does print(darkMode.value); inside onPressed shows the updated value? I may have a solution, if it does that. – Mearaj Jun 17 '23 at 02:39

0 Answers0