Skip to content

Commit cd0c6f4

Browse files
committed
Fixed null autovalidate assertion fail
1 parent 4e1a801 commit cd0c6f4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

example/lib/main.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class MyHomePageState extends State<MyHomePage> {
2727
var data;
2828
bool autoValidate = true;
2929
bool readOnly = false;
30+
GlobalKey<FormBuilderState> _fbKey = GlobalKey();
3031

3132
@override
3233
Widget build(BuildContext context) {
@@ -298,7 +299,7 @@ class MyHomePageState extends State<MyHomePage> {
298299
"Zambia",
299300
"Zimbabwe"
300301
];
301-
GlobalKey<FormBuilderState> _fbKey = GlobalKey();
302+
302303
return Scaffold(
303304
appBar: AppBar(
304305
title: Text('Flutter FormBuilder Example'),
@@ -310,7 +311,7 @@ class MyHomePageState extends State<MyHomePage> {
310311
Expanded(
311312
child: FormBuilder(
312313
context,
313-
// key: _fbKey,
314+
key: _fbKey,
314315
autovalidate: autoValidate,
315316
readonly: readOnly,
316317
// showResetButton: true,
@@ -555,6 +556,7 @@ class MyHomePageState extends State<MyHomePage> {
555556
MaterialButton(
556557
child: Text('External submit'),
557558
onPressed: () {
559+
print(_fbKey);
558560
_fbKey.currentState.save();
559561
if (_fbKey.currentState.validate()) {
560562
print(_fbKey.currentState.value);

lib/src/form_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class FormBuilderState extends State<FormBuilder> {
132132
hintText: formControl.hint,
133133
helperText: formControl.hint,
134134
),
135-
autovalidate: formControl.autovalidate,
135+
autovalidate: formControl.autovalidate ?? false,
136136
initialValue:
137137
formControl.value != null ? "${formControl.value}" : '',
138138
maxLines:

0 commit comments

Comments
 (0)