jonataslaw / getx

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

Program blocks on hot restart #2588

Open yaoing opened 2 years ago

yaoing commented 2 years ago

I've been using getx for state management, but after a recent code refactoring I had a hot restart blocking problem, and couldn't find the cause

Describe the bug The program works fine after initial startup or hot reload, but only after hot reboot it blocks, specifically, the program blocks and the interface cannot be clicked.

**Reproduction code

main.dart code

Future<void> initServices() async{
  await Get.putAsync<SharedPreferences>(() async {
    return await SharedPreferences.getInstance();
  }, permanent: true);
  await Get.putAsync(() async => ConfigService(), permanent: true);
  await Get.putAsync(() async => ModelService(), permanent: true);
  await Get.putAsync(() async => StorageService(), permanent: true);
}

void main(){
  initServices();

  runApp(
      GetMaterialApp(
          title: 'XXX'.tr,
          initialBinding: InitialBinding(),
         ...
         home: HomePage()

Flutter Version: flutter 3.3.4

Getx Version: get: ^4.6.1

Describe on which device you found the bug: Windows Desktop

jonataslaw commented 2 years ago

I need more details of your code to be sure where the problem could be. For now, you could adapt your project to the latest version of Flutter, where your main code should look something like this:

Future<void> main() async { 
WidgetsFlutterBinding.ensureInitialized();
await initServices();

Reason: You need to use this code whenever you have an asynchronous operation in your main. You need await initServices too, and main must be async

yaoing commented 2 years ago

Thanks for you reply!

I updated the flutter version and replaced the above code. Now the click event could executed while clicking, but the screen cannot be refreshed.

This doesn't seem to be a getx problem, but thanks for your help anyway!