getx icon indicating copy to clipboard operation
getx copied to clipboard

Theme() is not loading correctly on v4.1.3 but loads perfectly on v3.26.0.

Open iamshaunwu opened this issue 3 years ago • 25 comments

Theme() is not loading correctly on v4.1.3 but loads perfectly on v3.26.0.

On v4.1.3:

  • After upgrading, only amended a class to from Rx<User>() to Rxn<User>().
  • Ran the app and the themeData doesn't load with the custom fonts and appBar background colours that I had set.
  • I had to wrap each screen widget with Theme() and the theme data would load fine.
  • I did a flutter clean but it still doesn't work.

Downgraded to v3.26.0:

  • My themeData loads fine without the need to wrap each screen with Theme() again.
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(
      const SystemUiOverlayStyle(
        statusBarBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.dark,
      ),
    );
    return GestureDetector(
      onTap: () {
        final FocusScopeNode currentFocus = FocusScope.of(context);
        if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
          FocusManager.instance.primaryFocus.unfocus();
        }
      },
      child: GetMaterialApp(
        theme: themeData,  
        initialRoute: '/',
        getPages: AppRoutes.routes,
      ),
    );
  }
}

I am on Flutter v2.0.4.

iamshaunwu avatar Apr 04 '21 19:04 iamshaunwu

I had same issue here after upgrade to 4.1.3. woking well on 4.1.1

andoutica avatar Apr 05 '21 08:04 andoutica

Try this, it's worked for me:

GetMaterialApp(
      themeMode: ThemeMode.system,
      darkTheme: ThemeData.dark(),
      theme: ThemeData.light(),
)

15520065 avatar Apr 05 '21 10:04 15520065

Try this, it's worked for me:

GetMaterialApp(
      themeMode: ThemeMode.system,
      darkTheme: ThemeData.dark(),
      theme: ThemeData.light(),
)

Thanks! My phone is on Dark Mode. I set both theme: and darkTheme: to the same themeData and now it works.

        theme: themeData,
        darkTheme: themeData,

iamshaunwu avatar Apr 05 '21 11:04 iamshaunwu

related to https://github.com/jonataslaw/getx/pull/1262

jonataslaw avatar Apr 05 '21 13:04 jonataslaw

I would like to add that Get.changeTheme() stopped working as well.

davidpanic avatar Apr 06 '21 13:04 davidpanic

I would like to add that Get.changeTheme() stopped working as well.

@jonataslaw

iii6 avatar Apr 06 '21 13:04 iii6

changeTheme is still broken in 4.1.4.

Minimal reproduction (click to expand)
import 'package:flutter/material.dart';
import 'package:get/get.dart';

final _blueTheme = ThemeData(primarySwatch: Colors.blue);
final _greenTheme = ThemeData(primarySwatch: Colors.green);

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  final isGreen = false.obs;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('GetX bug'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Obx(
              () => Text('The primary color of this app should be: ${isGreen.value ? 'green' : 'blue'}.'),
            ),
            ElevatedButton(
              onPressed: () {
                isGreen.toggle();
                Get.changeTheme(isGreen.value ? _greenTheme : _blueTheme);
              },
              child: Text('Toggle'),
            ),
          ],
        ),
      ),
    );
  }
}

davidpanic avatar Apr 12 '21 08:04 davidpanic

@psrcek final isGreen = false.obs; Need extends GetxController

iii6 avatar Apr 12 '21 09:04 iii6

For this minimal reproduction example that is irrelevant. Putting the variable in a controller doesn't change anything, did you even try it before you blurted that out?

davidpanic avatar Apr 12 '21 09:04 davidpanic

@psrcek sorry. You’re right

iii6 avatar Apr 12 '21 09:04 iii6

@psrcek Can not reproduce error on your code

https://user-images.githubusercontent.com/35742643/115291472-316fac80-a12b-11eb-82c0-e7b1d5fb7f62.mov

jonataslaw avatar Apr 19 '21 19:04 jonataslaw

@jonataslaw

https://user-images.githubusercontent.com/61779498/115327921-5fec9680-a1c2-11eb-8216-d3d76ade0e78.mov

iii6 avatar Apr 20 '21 02:04 iii6

@jonataslaw I found the same problem as in the video above。

flymzero avatar Apr 20 '21 11:04 flymzero

RE: https://github.com/jonataslaw/getx/issues/1281#issuecomment-822722533

@jonataslaw this only happens if your system theme is set to dark mode, see https://github.com/jonataslaw/getx/issues/1281#issuecomment-822923237

davidpanic avatar Apr 20 '21 13:04 davidpanic

@jonataslaw

2021-04-20.10.13.50.mov

This is so confusing, but I was able to reproduce the problem by changing the device's ThemeMode. It seems that when the ThemeMode is changed, there is a block to changing the theme, I will investigate the reason for this to find out if it is a Flutter 2 or GetX failure. Whoever is facing the same problem can solve this by involving the GetMaterialApp in a GetBuilder and creating a ThemeController for it, but the ideal is not to depend on it

jonataslaw avatar Apr 20 '21 17:04 jonataslaw

@jonataslaw Getx v4.1.2 is ok

iii6 avatar Apr 20 '21 19:04 iii6

@eduardoflorence @GoldenSoju You who made changes to Get.changeTheme in the last two versions, could you help me with that?

jonataslaw avatar Apr 20 '21 19:04 jonataslaw

I was able to reproduce this behavior on Android emulator.

Please refer to the project below (check the TODO in order to break/fix the functionality): TEST PROJECT GITHUB

Since last year, after reading about it in the GetX Discord channel, I always call the if-else-statement below before calling Get.changeTheme() and it works also in the case of changing primarySwatch values.

    if (CustomThemes.availableSwatchThemes[count].brightness ==
        Brightness.dark) {
      Get.changeThemeMode(ThemeMode.dark);
    } else {
      Get.changeThemeMode(ThemeMode.light);
    }

GoldenSoju avatar Apr 25 '21 06:04 GoldenSoju

i am also facing same issue on get : 4.1.4. I noticed one thing when your device/system mode is in dark mode Get.changeTheme(); works but not able to update UI, when i save some file ( i.e hot reload) it shows change in theme, but when system mode is light it updates instantly (works perfect).

j33tmane avatar May 07 '21 14:05 j33tmane

i am also facing same issue on get : 4.1.4. I noticed one thing when your device/system mode is in dark mode Get.changeTheme(); works but not able to update UI, when i save some file ( i.e hot reload) it shows change in theme, but when system mode is light it updates instantly (works perfect).

void setTheme(ThemeData value) { if (darkTheme == null) { theme = value; } else { if (value.brightness == Brightness.light) { theme = value; } else { darkTheme = value; } } update(); }

Just have a look at the internal code block, I can't understand: if (darkTheme == null) { theme = value; } In this case, if the thememode is light and darktheme==null, the user call changeTheme(), it will only change darktheme but not touch that of theme which is actually using.

kevinxxq avatar Jun 23 '21 17:06 kevinxxq

I found a temporary solution, GetMaterialApp( //Add this line: themeMode: ThemeMode.light, )

vicentemrb avatar Jun 28 '21 01:06 vicentemrb

i am also facing same issue on get : 4.1.4. I noticed one thing when your device/system mode is in dark mode Get.changeTheme(); works but not able to update UI, when i save some file ( i.e hot reload) it shows change in theme, but when system mode is light it updates instantly (works perfect).

When applying Get.changeTheme (for me at least) it works like a charm, unfortunately, when calling Get.ChangeThemeMode theme is not applied correctly. This toss out Get.isDarkMode meaning as can't be called anymore.

maares avatar Aug 09 '21 11:08 maares

I am using getx: 4.1.4 I am also facing the same issue, but in my case it is working partially. When i switch the theme it changes the AppBar and BottomBar color but does not change the Scaffold color.

amitgeed avatar Aug 15 '21 06:08 amitgeed

I am using getx: 4.1.4 I am also facing the same issue, but in my case it is working partially. When i switch the theme it changes the AppBar and BottomBar color but does not change the Scaffold color.

I get this too, changing theme mode or just loading and Theme.of(context) is all wrong. Working fine on last run a couple months ago, no idea what's happened.

See below for an example. This is running in dark mode, while some pages work fine, others are totally broken.

The black tiles here are getting the right color from CupertinoTheme however the text and white background are inverted.

Looking into this more I see that Theme.of(context).brightness is always set to Light even when I have a dark background, very confusing...

Screenshot_20220131-222348.png

LucaJeevanjee avatar Jan 31 '22 22:01 LucaJeevanjee

Hi, any updates?

We have similar issue - after theme change

...
    isThemeDark.value = themeMode == ThemeMode.dark;

    Get.changeThemeMode(themeMode);

Immediately theme changed, but not completely, some items on screen are still with old theme elements (like buttons text). Changing route few times helps and when you're again on this screen - all is ok.

Are there any workarounds? Thanks.

alexandr-efimov avatar Dec 14 '23 21:12 alexandr-efimov