Im in a scenario that I need to receive data on a async task, then decide wether to navigate to the next page or not based on the replying.
But as far as I know, the state management in GetX support widget rebuild when value change in GetxController using .obs
and obx()
.
What should I do to observe the value change then trigger the navigation?
CodePudding user response:
You can us navigation in your async method or even in your method on complete call.
Suppose you call your async method and use dot then method you can put your response value in a varibale and can put conditions on it either it should navigate or not.
Future<int> getData()async{
print('Asynce Method');
return 1;
}
getData().then((result){
print(result);
if(result == 1){
// Navigate here
}
else{
// Don't Navigate
}
});
CodePudding user response:
It turns out a simple ever<T>
method inherited from the GetxController
class do the trick.
And it turns out that you shouldn't hybrid provider
, get_it
and get_x
all together. Bring lots of unnecessary pain which will cause some of the feature in get_x
not working.