@@ -13,17 +13,21 @@ class FormBuilder extends StatefulWidget {
13
13
final List <FormBuilderInput > controls;
14
14
final Function onSubmit;
15
15
final bool autovalidate;
16
+ final bool showResetButton;
16
17
final Widget submitButtonContent;
18
+ final Widget resetButtonContent;
17
19
18
20
const FormBuilder (
19
21
this .context, {
20
22
@required this .controls,
21
23
@required this .onSubmit,
22
24
this .onChanged,
23
25
this .autovalidate = false ,
26
+ this .showResetButton = false ,
24
27
this .onWillPop,
25
28
this .submitButtonContent,
26
- });
29
+ this .resetButtonContent,
30
+ }): assert (resetButtonContent == null || showResetButton);
27
31
28
32
@override
29
33
_FormBuilderState createState () => _FormBuilderState (controls);
@@ -41,7 +45,7 @@ class _FormBuilderState extends State<FormBuilder> {
41
45
return Form (
42
46
key: _formKey,
43
47
onChanged: widget.onChanged,
44
- //TODO: Allow user to update field value based on changes in others (e.g. Summations)
48
+ //TODO: Allow user to update field value or validate based on changes in others (e.g. Summations, Confirm Password )
45
49
onWillPop: widget.onWillPop,
46
50
autovalidate: widget.autovalidate,
47
51
child: ListView (
@@ -193,7 +197,6 @@ class _FormBuilderState extends State<FormBuilder> {
193
197
style: TextStyle (color: Colors .grey),
194
198
),
195
199
DropdownButton (
196
- //TODO: Is it possible to clear dropdown selection?
197
200
isExpanded: true ,
198
201
hint: Text (formControl.hint ?? '' ),
199
202
items: formControls[count].options.map ((option) {
@@ -700,19 +703,36 @@ class _FormBuilderState extends State<FormBuilder> {
700
703
701
704
formControlsList.add (Container (
702
705
margin: EdgeInsets .only (top: 10.0 ),
703
- child: MaterialButton (
704
- color: Theme .of (context).accentColor,
705
- textColor: Colors .white,
706
- onPressed: () {
707
- if (_formKey.currentState.validate ()) {
708
- _formKey.currentState.save ();
709
- widget.onSubmit (formData);
710
- } else {
711
- debugPrint ("Validation failed" );
712
- widget.onSubmit (null );
713
- }
714
- },
715
- child: widget.submitButtonContent ?? Text ('Submit' ),
706
+ child: Row (
707
+ children: [
708
+ widget.showResetButton ? Expanded (
709
+ child: OutlineButton (
710
+ borderSide: BorderSide (color: Theme .of (context).accentColor),
711
+ textColor: Theme .of (context).accentColor,
712
+ onPressed: () {
713
+ _formKey.currentState.reset (); //FIXME: only resets TextField based inputs
714
+ },
715
+ child: widget.resetButtonContent ?? Text ('Reset' ),
716
+ ),
717
+ ) : SizedBox (),
718
+ Expanded (
719
+ child: MaterialButton (
720
+ color: Theme .of (context).accentColor,
721
+ textColor: Colors .white,
722
+ onPressed: () {
723
+ if (_formKey.currentState.validate ()) {
724
+ _formKey.currentState.save ();
725
+ widget.onSubmit (formData);
726
+ } else {
727
+ debugPrint ("Validation failed" );
728
+ widget.onSubmit (null );
729
+ }
730
+ },
731
+ child: widget.submitButtonContent ?? Text ('Submit' ),
732
+ ),
733
+ ),
734
+
735
+ ],
716
736
),
717
737
));
718
738
0 commit comments