File tree Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,50 @@ Since this package makes use of [file_picker package](https://pub.dev/packages/f
35
35
),
36
36
```
37
37
38
+ On mobile platforms the file picker will open a default document picker if used with FileType.any.
39
+ If you want to be able to pick documents and images in the same form field you will need to define
40
+ different file types and thus different selectors. To achieve this use the typeSelectors parameter:
41
+ This way the user will see two buttons to open a file picker for documents and a file picker for the photos
42
+ gallery.
43
+
44
+ For example:
45
+
46
+ ``` dart
47
+ FormBuilderFilePicker(
48
+ name: "attachments",
49
+ previewImages: false,
50
+ allowMultiple: true,
51
+ withData: true,
52
+ typeSelectors: [
53
+ TypeSelector(
54
+ type: FileType.any,
55
+ selector: Row(
56
+ children: <Widget>[
57
+ Icon(Icons.add_circle),
58
+ Padding(
59
+ padding: const EdgeInsets.only(left: 8.0),
60
+ child: Text("Add documents"),
61
+ ),
62
+ ],
63
+ ),
64
+ ),
65
+ if (!kIsWeb)
66
+ TypeSelector(
67
+ type: FileType.image,
68
+ selector: Row(
69
+ children: <Widget>[
70
+ Icon(Icons.add_photo_alternate),
71
+ Padding(
72
+ padding: const EdgeInsets.only(left: 8.0),
73
+ child: Text("Add images"),
74
+ ),
75
+ ],
76
+ ),
77
+ ),
78
+ ],
79
+ )
80
+ ```
81
+
38
82
## Credits
39
83
40
84
<a href =" https://github.com/flutter-form-builder-ecosystem/form_builder_file_picker/graphs/contributors " >
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class TypeSelector {
24
24
final FileType type;
25
25
final Widget selector;
26
26
27
- TypeSelector ({required this .type, required this .selector});
27
+ const TypeSelector ({required this .type, required this .selector});
28
28
}
29
29
30
30
/// Field for image(s) from user device storage
@@ -91,8 +91,13 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
91
91
this .withReadStream = false ,
92
92
this .allowMultiple = false ,
93
93
this .previewImages = true ,
94
- this .selector = const Icon (Icons .add_circle),
95
- this .type = FileType .any,
94
+ @Deprecated ("please use typeSelectors for better picker and file type control" )
95
+ this .selector = const Icon (Icons .add_circle),
96
+ @Deprecated ("please use typeSelectors for better picker and file type control" )
97
+ this .type = FileType .any,
98
+ // TODO: once the above fields are removed typeSelectors should be made not null and initialized as
99
+ // const [TypeSelector(type: FileType.any, selector: Icon(Icons.add_circle))]
100
+ // the typeSelectorList variable can be then removed and we can use typeSelectors directly
96
101
this .typeSelectors,
97
102
this .allowedExtensions,
98
103
this .onFileLoading,
You can’t perform that action at this time.
0 commit comments