ming chen
ming chen

Reputation: 680

How do I observe a value change in a GetxController class and trigger navigation in the statelessWidget class using GetX in Flutter?

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?

Upvotes: 0

Views: 749

Answers (2)

ming chen
ming chen

Reputation: 680

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.

Upvotes: 1

Farhan Aslam
Farhan Aslam

Reputation: 31

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
}
});

Upvotes: 0

Related Questions