jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.39k stars 1.63k forks source link

GetX Get.changeTheme not update #3195

Open mdtuyen opened 2 months ago

mdtuyen commented 2 months ago

I use getX in my project, when changing theme, it doesn't work. Here is my code: From dialog choose theme:

onConfirm: () {
          SPUtils.to.saveTheme(theme: currentTheme);
          Get.changeTheme(AppTheme.keys[currentTheme]!);
          Navigator.pop(Get.overlayContext!, true);
        });

From Main:

return ScreenUtilInit(
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (_, __) {
          return GetMaterialApp(...)
        });

Screen order: Splash > HomeScreen

Home screen has 4 BottomNavigationBarItem, when I change theme by clicking on the item in the setting screen, the setting screen does not update the new theme, the theme only updates when I click to other bottom tabs

floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
              body: {4: ScanScreen(), 0: NaturalWorldScreen(), 1: MyIdScreen(), 2: ReminderScreen()}[indexPage.value] ??
                  SettingScreen(),
              bottomNavigationBar: BottomNavigationBar(
                type: BottomNavigationBarType.fixed,
                backgroundColor: Colors.white,
                items: [
                  BottomNavigationBarItem(
                      icon: IZIImage.icon(Icons.dataset, color: selectColor(indexPage.value == 0)), label: ''),
                  BottomNavigationBarItem(
                      icon: IZIImage.icon(Icons.favorite, color: selectColor(indexPage.value == 1)), label: ''),
                  BottomNavigationBarItem(
                      icon: IZIImage.icon(Icons.timer, color: selectColor(indexPage.value == 2)), label: ''),
                  BottomNavigationBarItem(
                      icon: IZIImage.icon(Icons.settings, color: selectColor(indexPage.value == 3)), label: ''),
                ],
                showSelectedLabels: false,
                showUnselectedLabels: false,
                currentIndex: indexPage.value > 3 ? 0 : indexPage.value,
                onTap: (index) {
                  selectIndex.add(indexPage);
                  indexPage.value = index;
                },
              ),
jonataslaw commented 2 months ago

Are you using the version 4?

xiaopindev commented 2 months ago

I also encountered the same problem, on the simulator is normal, on the real machine execution does not work.