@@ -144,9 +144,14 @@ typedef IgnoreChangeTest<S> = bool Function(S state);
144144/// This function is passed the `ViewModel` , and if `distinct` is `true` ,
145145/// it will only be called if the `ViewModel` changes.
146146///
147- /// This can be useful for imperative calls to things like Navigator,
148- /// TabController, etc
149- typedef OnWillChangeCallback <ViewModel > = void Function (ViewModel viewModel);
147+ /// This is useful for making calls to other classes, such as a
148+ /// `Navigator` or `TabController` , in response to state changes.
149+ /// It can also be used to trigger an action based on the previous
150+ /// state.
151+ typedef OnWillChangeCallback <ViewModel > = void Function (
152+ ViewModel previousViewModel,
153+ ViewModel newViewModel,
154+ );
150155
151156/// A function that will be run on State change, after the build method.
152157///
@@ -237,7 +242,8 @@ class StoreConnector<S, ViewModel> extends StatelessWidget {
237242 /// it will only be called if the `ViewModel` changes.
238243 ///
239244 /// This can be useful for imperative calls to things like Navigator,
240- /// TabController, etc
245+ /// TabController, etc. This can also be useful for triggering actions
246+ /// based on the previous state.
241247 final OnWillChangeCallback <ViewModel > onWillChange;
242248
243249 /// A function that will be run on State change, after the Widget is built.
@@ -337,7 +343,8 @@ class StoreBuilder<S> extends StatelessWidget {
337343 /// A function that will be run on State change, before the Widget is built.
338344 ///
339345 /// This can be useful for imperative calls to things like Navigator,
340- /// TabController, etc
346+ /// TabController, etc. This can also be useful for triggering actions
347+ /// based on the previous state.
341348 final OnWillChangeCallback <Store <S >> onWillChange;
342349
343350 /// A function that will be run on State change, after the Widget is built.
@@ -509,12 +516,12 @@ class _StoreStreamListenerState<S, ViewModel>
509516 }
510517
511518 void _handleChange (ViewModel vm, EventSink <ViewModel > sink) {
512- latestValue = vm;
513-
514519 if (widget.onWillChange != null ) {
515- widget.onWillChange (latestValue);
520+ widget.onWillChange (latestValue, vm );
516521 }
517522
523+ latestValue = vm;
524+
518525 if (widget.onDidChange != null ) {
519526 WidgetsBinding .instance.addPostFrameCallback ((_) {
520527 widget.onDidChange (latestValue);
0 commit comments