What is the recomended way to use ScopedModel in functions? Should i pass the model as an argument or should i always use ScopedModelDescendant wherever i used the model?
Using ScopedModelDescendant:
class Foo extends StatelessWidget {
Widget _buildItemThatNeedsModel() {
return ScopedModelDescendant<MyModel>(builder: (BuildContext context, Widget child, model) {
return Text(model.someDataFromModel);
},);
}
@override
Widget build(BuildContext context) {
return _buildItemThatNeedsModel();
}
}
Passing model as argument:
class Foo extends StatelessWidget {
Widget _buildItemThatNeedsModel(MyModel model) {
return Text(model.someDataFromModel);
}
@override
Widget build(BuildContext context) {
return ScopedModelDescendant<MyModel>(builder: (BuildContext context, Widget child, model) {
_buildItemThatNeedsModel(model);
},);
}
}
It seems to me that both of them gets the job done. If i have multiple functions that uses ScopedModel, then passing models as arguments seems like better way to do.
Which one should i use?