Pass arguments directly to a ViewModel when navigating
I've seen the question come up a few times around how to pass arguments to a ViewModel. Currently this is done by passing it to the View and then passing it into the viewModelBuilder that constructs the ViewModel.
This issue serves as a reminder to explore the syntax and code maintenance improvements that would bring, if any and then make a decision to see if it's worth adding this functionality.
what if you want to call a future with the argument data? i use an on model ready function is their a better way?
i usually done this
class ProfileViewModel extends FutureViewModel<void>{
final int id;
final _http = locator<HttpService>();
ProfileViewModel({this.id});
Future<void> futureToRun(){
return _http.get('/users/$id');
}
}
class ProfileView extends ViewModelBuilderWidget<ProfileViewModel>{
final int id;
ProfileView({this.id});
@override
ProfileViewModel viewModelBuilder(){
return ProfileViewModel(id: id);
}
}
@ajnaf that's perfectly fine. You can also pass your data into the constructor and pass it to the futureToRun as it's shown above.
This feature is not something we'll spend time on now. I think it's a good idea but the restrictions it'll add to the code is not something i'd like to tackle right now.