Skip to content

Commit c65acce

Browse files
committed
fix: use same function signature for default and custom file-viewer functions
1 parent 60ad53c commit c65acce

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/src/form_builder_file_picker.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
8787
this.type = FileType.any,
8888
this.allowedExtensions,
8989
this.onFileLoading,
90-
this.allowCompression = false,
90+
this.allowCompression = true,
9191
this.customFileViewerBuilder,
9292
}) : super(
9393
key: key,
@@ -129,7 +129,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
129129
? customFileViewerBuilder.call(state._files,
130130
(files) => state._setFiles(files ?? [], field))
131131
: state.defaultFileViewer(state._files,
132-
field as FormFieldState<List<PlatformFile>>),
132+
(files) => state._setFiles(files ?? [], field)),
133133
],
134134
),
135135
);
@@ -206,11 +206,8 @@ class _FormBuilderFilePickerState
206206

207207
void _setFiles(
208208
List<PlatformFile> files, FormFieldState<List<PlatformFile>?> field) {
209-
setState(() {
210-
_files = files;
211-
});
209+
setState(() => _files = files);
212210
field.didChange(_files);
213-
widget.onChanged?.call(_files);
214211
}
215212

216213
void removeFileAtIndex(int index, FormFieldState<List<PlatformFile>> field) {
@@ -219,7 +216,7 @@ class _FormBuilderFilePickerState
219216
}
220217

221218
Widget defaultFileViewer(
222-
List<PlatformFile> files, FormFieldState<List<PlatformFile>> field) {
219+
List<PlatformFile> files, FormFieldSetter<List<PlatformFile>> setter) {
223220
final theme = Theme.of(context);
224221

225222
return LayoutBuilder(
@@ -277,7 +274,10 @@ class _FormBuilderFilePickerState
277274
top: 0,
278275
right: 0,
279276
child: InkWell(
280-
onTap: () => removeFileAtIndex(index, field),
277+
onTap: () {
278+
files.removeAt(index);
279+
setter.call([...files]);
280+
},
281281
child: Container(
282282
margin: const EdgeInsets.all(3),
283283
decoration: BoxDecoration(

0 commit comments

Comments
 (0)