2

I want to add the parameter to GetxController's onInit method, and pass it whenever the controller init, how to achieve this code?

class TestModel extends GetxController {
  @override
  void onInit(String token) {
    fetchApi(token);
    super.onInit();
  }
  ...
}
ccd
  • 5,788
  • 10
  • 46
  • 96
  • Why don't you create a variable and create a constructor for the controller then use it in the onInit? – Yahya Oct 28 '21 at 15:53

1 Answers1

2

You can use constructor like this:

class TestModel extends GetxController{
 final String token;
 TestModel(this.token);

 @override
 void onInit() {
   fetchApi(token);
   super.onInit();
 }
 ...
}
S. M. JAHANGIR
  • 4,324
  • 1
  • 10
  • 30