@@ -144,9 +144,14 @@ typedef IgnoreChangeTest<S> = bool Function(S state);
144
144
/// This function is passed the `ViewModel` , and if `distinct` is `true` ,
145
145
/// it will only be called if the `ViewModel` changes.
146
146
///
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
+ );
150
155
151
156
/// A function that will be run on State change, after the build method.
152
157
///
@@ -237,7 +242,8 @@ class StoreConnector<S, ViewModel> extends StatelessWidget {
237
242
/// it will only be called if the `ViewModel` changes.
238
243
///
239
244
/// 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.
241
247
final OnWillChangeCallback <ViewModel > onWillChange;
242
248
243
249
/// A function that will be run on State change, after the Widget is built.
@@ -337,7 +343,8 @@ class StoreBuilder<S> extends StatelessWidget {
337
343
/// A function that will be run on State change, before the Widget is built.
338
344
///
339
345
/// 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.
341
348
final OnWillChangeCallback <Store <S >> onWillChange;
342
349
343
350
/// A function that will be run on State change, after the Widget is built.
@@ -509,12 +516,12 @@ class _StoreStreamListenerState<S, ViewModel>
509
516
}
510
517
511
518
void _handleChange (ViewModel vm, EventSink <ViewModel > sink) {
512
- latestValue = vm;
513
-
514
519
if (widget.onWillChange != null ) {
515
- widget.onWillChange (latestValue);
520
+ widget.onWillChange (latestValue, vm );
516
521
}
517
522
523
+ latestValue = vm;
524
+
518
525
if (widget.onDidChange != null ) {
519
526
WidgetsBinding .instance.addPostFrameCallback ((_) {
520
527
widget.onDidChange (latestValue);
0 commit comments