Skip to content

Commit 9d20f9c

Browse files
Merge pull request #41 from flutter-form-builder-ecosystem/14
fix: Reset preview when reset form field
2 parents 6edcf1d + b537029 commit 9d20f9c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

example/lib/main.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ class MyHomePageState extends State<MyHomePage> {
8585
() => _useCustomFileViewer = !_useCustomFileViewer);
8686
},
8787
),
88+
const Spacer(),
89+
ElevatedButton(
90+
child: const Text('Reset'),
91+
onPressed: () {
92+
setState(
93+
() => _formKey.currentState!.reset(),
94+
);
95+
},
96+
),
8897
],
8998
),
9099
],

lib/src/form_builder_file_picker.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ class _FormBuilderFilePickerState
248248
final itemSize =
249249
(constraints.biggest.width - (count * spacing)) / count;
250250
return Wrap(
251-
// scrollDirection: Axis.horizontal,
252251
alignment: WrapAlignment.start,
253252
runAlignment: WrapAlignment.start,
254253
runSpacing: 10,
@@ -352,4 +351,10 @@ class _FormBuilderFilePickerState
352351
return Icons.insert_drive_file;
353352
}
354353
}
354+
355+
@override
356+
void reset() {
357+
super.reset();
358+
setState(() => _files = widget.initialValue ?? []);
359+
}
355360
}

0 commit comments

Comments
 (0)