Skip to content

Commit c876cfb

Browse files
Merge pull request #20 from Bdaya-Dev/main
Added missing documentation and improved displaying images
2 parents b0f8d3c + fe94363 commit c876cfb

File tree

2 files changed

+283
-152
lines changed

2 files changed

+283
-152
lines changed

example/lib/main.dart

Lines changed: 96 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,41 +48,103 @@ class MyHomePage extends StatelessWidget {
4848
child: Center(
4949
child: FormBuilder(
5050
key: _formKey,
51-
child: Column(
52-
mainAxisAlignment: MainAxisAlignment.center,
53-
children: <Widget>[
54-
FormBuilderImagePicker(
55-
name: 'photos',
56-
displayCustomType: (obj) =>
57-
obj is ApiImage ? obj.imageUrl : obj,
58-
decoration: const InputDecoration(labelText: 'Pick Photos'),
59-
maxImages: 5,
60-
initialValue: [
61-
'https://images.pexels.com/photos/7078045/pexels-photo-7078045.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
62-
const Text('this is an image\nas a widget !'),
63-
ApiImage(
64-
id: 'whatever',
65-
imageUrl:
66-
'https://images.pexels.com/photos/8311418/pexels-photo-8311418.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260',
51+
child: SingleChildScrollView(
52+
child: Column(
53+
mainAxisAlignment: MainAxisAlignment.center,
54+
children: <Widget>[
55+
FormBuilderImagePicker(
56+
name: 'photos',
57+
displayCustomType: (obj) =>
58+
obj is ApiImage ? obj.imageUrl : obj,
59+
decoration: const InputDecoration(labelText: 'Pick Photos'),
60+
maxImages: 5,
61+
previewAutoSizeWidth: true,
62+
previewMargin: const EdgeInsetsDirectional.only(end: 8),
63+
fit: BoxFit.cover,
64+
initialValue: [
65+
'https://images.pexels.com/photos/7078045/pexels-photo-7078045.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
66+
const Text('this is an image\nas a widget !'),
67+
ApiImage(
68+
id: 'whatever',
69+
imageUrl:
70+
'https://images.pexels.com/photos/8311418/pexels-photo-8311418.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260',
71+
),
72+
],
73+
),
74+
const SizedBox(height: 15),
75+
FormBuilderImagePicker(
76+
name: 'singlePhotoWithDecoration',
77+
displayCustomType: (obj) =>
78+
obj is ApiImage ? obj.imageUrl : obj,
79+
decoration: const InputDecoration(
80+
labelText: 'Pick Single Photo With Decoration Visible',
6781
),
68-
],
69-
),
70-
const SizedBox(height: 15),
71-
ElevatedButton(
72-
child: const Text('Submit'),
73-
onPressed: () {
74-
if (_formKey.currentState?.saveAndValidate() == true) {
75-
debugPrint(_formKey.currentState!.value.toString());
76-
}
77-
},
78-
),
79-
ElevatedButton(
80-
child: const Text('Reset'),
81-
onPressed: () {
82-
_formKey.currentState?.reset();
83-
},
84-
)
85-
],
82+
showDecoration: true,
83+
maxImages: 1,
84+
previewAutoSizeWidth: true,
85+
initialValue: const [
86+
'https://images.pexels.com/photos/7078045/pexels-photo-7078045.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
87+
],
88+
),
89+
const SizedBox(height: 15),
90+
const Text(
91+
'Single Photo with no decoration, and previewAutoSizeWidth=true'),
92+
FormBuilderImagePicker(
93+
name: 'singlePhoto',
94+
displayCustomType: (obj) =>
95+
obj is ApiImage ? obj.imageUrl : obj,
96+
// decoration: const InputDecoration(
97+
// labelText: 'Pick Photos',
98+
// ),
99+
showDecoration: false,
100+
maxImages: 1,
101+
previewAutoSizeWidth: true,
102+
initialValue: const [
103+
'https://images.pexels.com/photos/7078045/pexels-photo-7078045.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
104+
],
105+
),
106+
const SizedBox(height: 15),
107+
const Text(
108+
'Single Photo similar to CircleAvatar, using transformImageWidget',
109+
),
110+
FormBuilderImagePicker(
111+
name: 'singleAvatarPhoto',
112+
displayCustomType: (obj) =>
113+
obj is ApiImage ? obj.imageUrl : obj,
114+
decoration: const InputDecoration(
115+
labelText: 'Pick Photos',
116+
),
117+
transformImageWidget: (context, displayImage) => Card(
118+
shape: const CircleBorder(),
119+
clipBehavior: Clip.antiAlias,
120+
child: SizedBox.expand(
121+
child: displayImage,
122+
),
123+
),
124+
showDecoration: false,
125+
maxImages: 1,
126+
previewAutoSizeWidth: false,
127+
initialValue: const [
128+
'https://images.pexels.com/photos/7078045/pexels-photo-7078045.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
129+
],
130+
),
131+
const SizedBox(height: 15),
132+
ElevatedButton(
133+
child: const Text('Submit'),
134+
onPressed: () {
135+
if (_formKey.currentState?.saveAndValidate() == true) {
136+
debugPrint(_formKey.currentState!.value.toString());
137+
}
138+
},
139+
),
140+
ElevatedButton(
141+
child: const Text('Reset'),
142+
onPressed: () {
143+
_formKey.currentState?.reset();
144+
},
145+
)
146+
],
147+
),
86148
),
87149
),
88150
),

0 commit comments

Comments
 (0)