getx
getx copied to clipboard
Theme() is not loading correctly on v4.1.3 but loads perfectly on v3.26.0.
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.
I had same issue here after upgrade to 4.1.3. woking well on 4.1.1
Try this, it's worked for me:
GetMaterialApp(
themeMode: ThemeMode.system,
darkTheme: ThemeData.dark(),
theme: ThemeData.light(),
)
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,
related to https://github.com/jonataslaw/getx/pull/1262
I would like to add that Get.changeTheme()
stopped working as well.
I would like to add that
Get.changeTheme()
stopped working as well.
@jonataslaw
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'),
),
],
),
),
);
}
}
@psrcek
final isGreen = false.obs;
Need extends GetxController
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?
@psrcek sorry. You’re right
@psrcek Can not reproduce error on your code
https://user-images.githubusercontent.com/35742643/115291472-316fac80-a12b-11eb-82c0-e7b1d5fb7f62.mov
@jonataslaw
https://user-images.githubusercontent.com/61779498/115327921-5fec9680-a1c2-11eb-8216-d3d76ade0e78.mov
@jonataslaw I found the same problem as in the video above。
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
@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 Getx v4.1.2
is ok
@eduardoflorence @GoldenSoju You who made changes to Get.changeTheme in the last two versions, could you help me with that?
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);
}
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).
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.
I found a temporary solution, GetMaterialApp( //Add this line: themeMode: ThemeMode.light, )
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.
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 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...
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.