@@ -71,34 +71,39 @@ class FormBuilderFilePicker
71
71
/// to support user interactions with the picked files.
72
72
final FileViewerBuilder ? customFileViewerBuilder;
73
73
74
+ /// Allow to customise the view of the pickers.
75
+ final Widget Function (List <Widget > types)? customTypeViewerBuilder;
76
+
74
77
/// Creates field for image(s) from user device storage
75
- FormBuilderFilePicker ({
76
- //From Super
77
- super .key,
78
- required super .name,
79
- super .validator,
80
- super .initialValue,
81
- super .decoration,
82
- super .onChanged,
83
- super .valueTransformer,
84
- super .enabled,
85
- super .onSaved,
86
- super .autovalidateMode = AutovalidateMode .disabled,
87
- super .onReset,
88
- super .focusNode,
89
- this .maxFiles,
90
- this .withData = kIsWeb,
91
- this .withReadStream = false ,
92
- this .allowMultiple = false ,
93
- this .previewImages = true ,
94
- this .typeSelectors = const [
95
- TypeSelector (type: FileType .any, selector: Icon (Icons .add_circle))
96
- ],
97
- this .allowedExtensions,
98
- this .onFileLoading,
99
- this .allowCompression = true ,
100
- this .customFileViewerBuilder,
101
- }) : super (
78
+ FormBuilderFilePicker (
79
+ {
80
+ //From Super
81
+ super .key,
82
+ required super .name,
83
+ super .validator,
84
+ super .initialValue,
85
+ super .decoration,
86
+ super .onChanged,
87
+ super .valueTransformer,
88
+ super .enabled,
89
+ super .onSaved,
90
+ super .autovalidateMode = AutovalidateMode .disabled,
91
+ super .onReset,
92
+ super .focusNode,
93
+ this .maxFiles,
94
+ this .withData = kIsWeb,
95
+ this .withReadStream = false ,
96
+ this .allowMultiple = false ,
97
+ this .previewImages = true ,
98
+ this .typeSelectors = const [
99
+ TypeSelector (type: FileType .any, selector: Icon (Icons .add_circle))
100
+ ],
101
+ this .allowedExtensions,
102
+ this .onFileLoading,
103
+ this .allowCompression = true ,
104
+ this .customFileViewerBuilder,
105
+ this .customTypeViewerBuilder})
106
+ : super (
102
107
builder: (FormFieldState <List <PlatformFile >?> field) {
103
108
final state = field as _FormBuilderFilePickerState ;
104
109
@@ -109,21 +114,14 @@ class FormBuilderFilePicker
109
114
: null ),
110
115
child: Column (
111
116
children: < Widget > [
112
- Row (
113
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
114
- children: < Widget > [
115
- ...typeSelectors.map (
116
- (typeSelector) => InkWell (
117
- onTap: state.enabled &&
118
- (null == state._remainingItemCount ||
119
- state._remainingItemCount! > 0 )
120
- ? () => state.pickFiles (field, typeSelector.type)
121
- : null ,
122
- child: typeSelector.selector,
117
+ customTypeViewerBuilder != null
118
+ ? customTypeViewerBuilder (
119
+ state.getTypeSelectorActions (typeSelectors, field))
120
+ : Row (
121
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
122
+ children: state.getTypeSelectorActions (
123
+ typeSelectors, field),
123
124
),
124
- ),
125
- ],
126
- ),
127
125
const SizedBox (height: 3 ),
128
126
customFileViewerBuilder != null
129
127
? customFileViewerBuilder.call (state._files,
@@ -305,6 +303,21 @@ class _FormBuilderFilePickerState extends FormBuilderFieldDecorationState<
305
303
);
306
304
}
307
305
306
+ List <Widget > getTypeSelectorActions (List <TypeSelector > typeSelectors,
307
+ FormFieldState <List <PlatformFile >?> field) {
308
+ return < Widget > [
309
+ ...typeSelectors.map (
310
+ (typeSelector) => InkWell (
311
+ onTap: enabled &&
312
+ (null == _remainingItemCount || _remainingItemCount! > 0 )
313
+ ? () => pickFiles (field, typeSelector.type)
314
+ : null ,
315
+ child: typeSelector.selector,
316
+ ),
317
+ ),
318
+ ];
319
+ }
320
+
308
321
IconData getIconData (String fileExtension) {
309
322
final lowerCaseFileExt = fileExtension.toLowerCase ();
310
323
if (imageFileExts.contains (lowerCaseFileExt)) return Icons .image;
0 commit comments