jonataslaw / getx

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

Get.to not working when awaiting aType response from Get. #2911

Open gauravmehta13 opened 1 year ago

gauravmehta13 commented 1 year ago

Describe the bug The Get.to works fine when calling the class but if we await the response in a particular type then it doesnt

Reproduction code

example:

This doesn't work

onTap: () async {
                final bool? completed = await Get.to(() => MetricPage());
                if (completed == true) state.getDetails();
              },

But this works

onTap: () async {
                final completed = await Get.to(() => MetricPage());
                if (completed == true) state.getDetails();
              },

To Reproduce Just call the navigation code like above it will throw this error image

Flutter Version: 3.13

Getx Version: get: ^5.0.0-release-candidate-5

EmadBeltaje commented 1 year ago

now the problem is that you are awaiting for dynamic value not bool because Get.to return dynamic value (you may ask how! because i want to return bool), ok but lets say the page was closed by back button or you just typed Get.back() and forgot to return anything this mean the return value is not bool its (void) which is type of dynamic, so the error is not related to GetX its type error

gauravmehta13 commented 1 year ago

Then how come it works with Flutter Navigator @EmadBeltaje Also there is a way to specify the type that we are planning to return but that also doesnt work.

final bool? completed = await Get.to<bool>(() => MetricPage());

Moreover if the page was closed by back button or you just typed Get.back() and forgot to return anything, Then it returns null and not void.

EmadBeltaje commented 1 year ago

Then how come it works with Flutter Navigator @EmadBeltaje Also there is a way to specify the type that we are planning to return but that also doesnt work.

final bool? completed = await Get.to<bool>(() => MetricPage());

Moreover if the page was closed by back button or you just typed Get.back() and forgot to return anything, Then it returns null and not void.

Is there a way to specify the return type: Sadly No in flutter navigator you can specify the type using generic but in Getx the safe way to deal with it is

final result = await Get.to(() => MyPage());

// you can also check for the type here
if(result != null){
    // run any action here..
}
jonataslaw commented 1 year ago

I have a fix for that, I will send asap