'transfer from Provider to Getx Error: 1 positional argument(s) expected, but 0 found

Im new to flutter and download a code which is using Provider, now I tried to transfer to use getxcontroller,

here is original code with Provider:

class BrowserModel extends ChangeNotifier {
  BrowserModel(currentWebViewModel) {
    this._currentWebViewModel = currentWebViewModel;
  }
  //code
}

And here is implement provider:

var browserModel = Provider.of<BrowserModel>(context, listen: true);

What I did is simply transferring to GetxController:

class BrowserModel extends GetxController {
  BrowserModel(currentWebViewModel) {
    this._currentWebViewModel = currentWebViewModel;
  }

}

By implementing this GetxController I met following error:

Error: 1 positional argument(s) expected, but 0 found

So my question I noticed by BrowserModel there must be a argument currentWebViewModel, so what I can do now is as followings:

    class BrowserModel extends GetxController {
      BrowserModel({currentWebViewModel}) {
        this._currentWebViewModel = currentWebViewModel;
      }
}

so currentWebViewModel could be null, but I am not sure if this is the right way to handle from Provider to Getx, I hope my expression is easy to understand, and thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source