@@ -9,17 +9,38 @@ class FormBuilder extends StatefulWidget {
9
9
/// will rebuild.
10
10
final VoidCallback ? onChanged;
11
11
12
- /// Enables the form to veto attempts by the user to dismiss the [ModalRoute]
13
- /// that contains the form.
12
+ /// {@macro flutter.widgets.navigator.onPopInvoked}
14
13
///
15
- /// If the callback returns a Future that resolves to false, the form's route
16
- /// will not be popped.
14
+ /// {@tool dartpad}
15
+ /// This sample demonstrates how to use this parameter to show a confirmation
16
+ /// dialog when a navigation pop would cause form data to be lost.
17
+ ///
18
+ /// ** See code in examples/api/lib/widgets/form/form.1.dart **
19
+ /// {@end-tool}
17
20
///
18
21
/// See also:
19
22
///
20
- /// * [WillPopScope] , another widget that provides a way to intercept the
23
+ /// * [canPop] , which also comes from [PopScope] and is often used in
24
+ /// conjunction with this parameter.
25
+ /// * [PopScope.onPopInvoked] , which is what [Form] delegates to internally.ther widget that provides a way to intercept the
21
26
/// back button.
22
- final WillPopCallback ? onWillPop;
27
+ final void Function (bool )? onPopInvoked;
28
+
29
+ /// {@macro flutter.widgets.PopScope.canPop}
30
+ ///
31
+ /// {@tool dartpad}
32
+ /// This sample demonstrates how to use this parameter to show a confirmation
33
+ /// dialog when a navigation pop would cause form data to be lost.
34
+ ///
35
+ /// ** See code in examples/api/lib/widgets/form/form.1.dart **
36
+ /// {@end-tool}
37
+ ///
38
+ /// See also:
39
+ ///
40
+ /// * [onPopInvoked] , which also comes from [PopScope] and is often used in
41
+ /// conjunction with this parameter.
42
+ /// * [PopScope.canPop] , which is what [Form] delegates to internally.
43
+ final bool ? canPop;
23
44
24
45
/// The widget below this widget in the tree.
25
46
///
@@ -81,11 +102,12 @@ class FormBuilder extends StatefulWidget {
81
102
required this .child,
82
103
this .onChanged,
83
104
this .autovalidateMode,
84
- this .onWillPop ,
105
+ this .onPopInvoked ,
85
106
this .initialValue = const < String , dynamic > {},
86
107
this .skipDisabled = false ,
87
108
this .enabled = true ,
88
109
this .clearValueOnUnregister = false ,
110
+ this .canPop,
89
111
});
90
112
91
113
static FormBuilderState ? of (BuildContext context) =>
@@ -315,7 +337,8 @@ class FormBuilderState extends State<FormBuilder> {
315
337
return Form (
316
338
key: _formKey,
317
339
autovalidateMode: widget.autovalidateMode,
318
- onWillPop: widget.onWillPop,
340
+ onPopInvoked: widget.onPopInvoked,
341
+ canPop: widget.canPop,
319
342
// `onChanged` is called during setInternalFieldValue else will be called early
320
343
child: _FormBuilderScope (
321
344
formState: this ,
0 commit comments