OnWillChangeCallback<ViewModel> typedef
OnWillChangeCallback<ViewModel> =
void Function(ViewModel? previousViewModel, ViewModel newViewModel)
A function that will be run on State change, before the build method.
This function is passed the previous and current ViewModel
, and if
distinct
is true
, it will only be called when the ViewModel
changes.
This is useful for making calls to other classes, such as a
Navigator
or TabController
, in response to state changes.
It can also be used to trigger an action based on the previous
state.
StoreConnector<String, String>(
converter: (store) => store.state,
onWillChange: (prev, vm) {
if (prev != vm) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(vm),
));
}
},
builder: (context, vm) {
return Text(vm);
},
);
Implementation
typedef OnWillChangeCallback<ViewModel> = void Function(
ViewModel? previousViewModel,
ViewModel newViewModel,
);