Skip to content

Commit 21a0007

Browse files
committed
[FEATURE] Allow to customise the view of pickers
1 parent eee7332 commit 21a0007

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

example/lib/main.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class MyHomePageState extends State<MyHomePage> {
5858
),
5959
)
6060
],
61+
customTypeViewerBuilder: (children) => Row(
62+
mainAxisAlignment: MainAxisAlignment.end,
63+
children: children,
64+
),
6165
onFileLoading: (val) {
6266
debugPrint(val.toString());
6367
},

lib/src/form_builder_file_picker.dart

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class FormBuilderFilePicker
7171
/// to support user interactions with the picked files.
7272
final FileViewerBuilder? customFileViewerBuilder;
7373

74+
/// Allow to customise the view of the pickers.
75+
final Widget Function(List<Widget> types)? customTypeViewerBuilder;
76+
7477
/// Creates field for image(s) from user device storage
7578
FormBuilderFilePicker({
7679
//From Super
@@ -98,6 +101,7 @@ class FormBuilderFilePicker
98101
this.onFileLoading,
99102
this.allowCompression = true,
100103
this.customFileViewerBuilder,
104+
this.customTypeViewerBuilder
101105
}) : super(
102106
builder: (FormFieldState<List<PlatformFile>?> field) {
103107
final state = field as _FormBuilderFilePickerState;
@@ -109,20 +113,11 @@ class FormBuilderFilePicker
109113
: null),
110114
child: Column(
111115
children: <Widget>[
112-
Row(
116+
customTypeViewerBuilder != null
117+
? customTypeViewerBuilder(state.getTypeSelectorActions(typeSelectors, field))
118+
: Row(
113119
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,
123-
),
124-
),
125-
],
120+
children: state.getTypeSelectorActions(typeSelectors, field),
126121
),
127122
const SizedBox(height: 3),
128123
customFileViewerBuilder != null
@@ -305,6 +300,22 @@ class _FormBuilderFilePickerState extends FormBuilderFieldDecorationState<
305300
);
306301
}
307302

303+
List<Widget> getTypeSelectorActions(List<TypeSelector> typeSelectors, FormFieldState<List<PlatformFile>?> field) {
304+
return <Widget>[
305+
...typeSelectors.map(
306+
(typeSelector) =>
307+
InkWell(
308+
onTap: enabled &&
309+
(null == _remainingItemCount ||
310+
_remainingItemCount! > 0)
311+
? () => pickFiles(field, typeSelector.type)
312+
: null,
313+
child: typeSelector.selector,
314+
),
315+
),
316+
];
317+
}
318+
308319
IconData getIconData(String fileExtension) {
309320
final lowerCaseFileExt = fileExtension.toLowerCase();
310321
if (imageFileExts.contains(lowerCaseFileExt)) return Icons.image;

0 commit comments

Comments
 (0)