getx
getx copied to clipboard
Get.updateLocal() has an apparent death bug
Describe the bug It seems the function Get.updateLocal() has an apparent death bug.
I put a PopupMenuButton widget on the appbar, and add serveral PopupMenuItem inside to change language.
Mostly it works very well, but sometimes when I click the menu item, the total UI freezed.
I paster the key code and image below, hope you'll find the bug.
**code
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
enableLog: true,
title: 'Demo',
// 主题
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
themeMode: ThemeMode.system,
// 语言
translations: AppTranslations(),
locale: Get.deviceLocale,
fallbackLocale: Locale('en', 'US'), // 若app内未内置该local语言, 则用en_US替代
// 页面跳转方式
defaultTransition: Transition.cupertino,
home: Home(),
);
}
}
class Home extends StatelessWidget {
final CountController c = Get.put(CountController());
@override
Widget build(context) {
return Scaffold(
appBar: AppBar(
title: Obx(() => Text("Clicks: ${c.count}")),
actions: [MyMenu()],
),
);
}
}
class MyMenu extends StatelessWidget {
menuTitle(BuildContext context, String title) {
return PopupMenuItem(
enabled: false,
height: 10,
child: Row(
children: [
Text(title),
SizedBox(width: 10),
Flexible(child: Divider(color: Theme.of(context).accentColor)),
],
),
);
}
menuItem(String value, String desc) {
return PopupMenuItem(
value: value,
child: Align(alignment: Alignment.centerRight, child: Text(desc)),
);
}
@override
Widget build(BuildContext context) {
return PopupMenuButton(
icon: Icon(Icons.more_horiz),
offset: Offset(0, 30),
itemBuilder: (context) => <PopupMenuEntry>[
//
menuTitle(context, LocalString.theme.tr),
menuItem(LocalString.lightTheme, LocalString.lightTheme.tr),
menuItem(LocalString.darkTheme, LocalString.darkTheme.tr),
// menuItem(LocalString.systemTheme, LocalString.systemTheme.tr),
//
menuTitle(context, LocalString.language.tr),
menuItem('en', 'English'),
menuItem('fr', 'Français'),
menuItem('zh', '简体中文'),
// menuItem('device', LocalString.systemLanguage.tr),
],
onSelected: (value) {
switch (value) {
case LocalString.lightTheme:
Get.changeThemeMode(ThemeMode.light);
break;
case LocalString.darkTheme:
Get.changeThemeMode(ThemeMode.dark);
break;
case LocalString.systemTheme:
Get.changeThemeMode(ThemeMode.system);
break;
case 'en':
Get.updateLocale(Locale('en', 'US'));
break;
case 'fr':
Get.updateLocale(Locale('fr', 'FR'));
break;
case 'zh':
Get.updateLocale(Locale('zh', 'CN'));
break;
case 'device':
Get.updateLocale(Get.deviceLocale);
break;
}
},
);
}
}
Screenshots If applicable, add screenshots to help explain your problem.
Flutter Version: PS D:\Study\demo04> flutter --version Flutter 1.23.0-18.1.pre • channel beta • https://github.com/flutter/flutter.git Framework • revision 198df796aa (10 weeks ago) • 2020-10-15 12:04:33 -0700 Engine • revision 1d12d82d9c Tools • Dart 2.11.0 (build 2.11.0-213.1.beta)
Getx Version: get: ^3.23.1
Describe on which device you found the bug: web and google android simulator
similar issue: https://github.com/jonataslaw/getx/issues/737
my issue represent on emulator and meizu note 9
@jonataslaw, I confirmed that the problem happens and put a smaller code to reproduce below. I can only reproduce the problem (freezes the UI) after clicking approximately 15 times in each language.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
translations: AppTranslations(),
locale: Get.deviceLocale,
fallbackLocale: Locale('en', 'US'),
defaultTransition: Transition.cupertino,
home: Home(),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(context) {
return Scaffold(
appBar: AppBar(
title: Text("${'hello'.tr}"),
actions: [MyMenu()],
),
);
}
}
class MyMenu extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PopupMenuButton(
icon: Icon(Icons.more_horiz),
offset: Offset(0, 30),
itemBuilder: (context) => <PopupMenuEntry>[
PopupMenuItem(
value: 'en',
child: Text('English'),
),
PopupMenuItem(
value: 'de',
child: Text('German'),
),
PopupMenuItem(
value: 'pt',
child: Text('Portuguese'),
),
],
onSelected: (value) {
switch (value) {
case 'en':
Get.updateLocale(Locale('en', 'US'));
break;
case 'de':
Get.updateLocale(Locale('de', 'DE'));
break;
case 'pt':
Get.updateLocale(Locale('pt', 'BR'));
break;
}
},
);
}
}
class AppTranslations extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'en_US': {
'hello': 'Hello World',
},
'de_DE': {
'hello': 'Hallo Welt',
},
'pt_BR': {
'hello': 'Alo Mundo',
},
};
}
Okay, this looks like an error with the Flutter Engine. I need to know what devices this is on to investigate further, or open an issue in the official repository, because I cannot reproduce this on my devices.
https://user-images.githubusercontent.com/35742643/103312433-c6735c00-49fb-11eb-9eb5-ed92e9d38bac.mp4
I suppose the engine's lockEvents function is blocking the ring longer than necessary which gives the impression of locking on some devices. I just made a modification to access the hot reload api directly on the master, if you can test it, I would be grateful.
I tested using GetX on the master branch and the same problem occurs. I don't use an emulator, I test directly on a Samsung cell phone model Galaxy A01 (SM-A015M / DS). I made the video below to show the interface freeze
https://user-images.githubusercontent.com/9120528/103320868-d4ce7180-4a15-11eb-9b40-bba3c381240c.mp4
Same Issue found for me.
Same Issue. Has anybody got a solution?