Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - How to use mounted in GetX

I initiate network request in GetXController, after network call back, I should judge this controller/this page is dealloc or not. If this page is not dealloced, update Page. If this page is dealloced, I do noting. As I know, I can write below codes in flutter origin:

if (mounted) {
   // update page
   setState({
   });
}

So my question is how to write in GetX controller?

like image 326
zhouxinle Avatar asked Dec 12 '25 23:12

zhouxinle


1 Answers

There is a property called isClosed in GetxController so you can use it instead of mounted

class MyController extends GetxController{
...
  fun() {
    // some code
    if(this.isClosed) return;
    // code that you want not execute it
  }
...
}
like image 176
Mohammad Enawe Avatar answered Dec 14 '25 12:12

Mohammad Enawe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!