Skip to content

Commit da96d41

Browse files
committed
Added delete icon on selected images in ImagePicker instead of non-intuitive long-press to delete. Closes #278
1 parent 2fc345c commit da96d41

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

lib/src/fields/form_builder_image_picker.dart

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,39 @@ class _FormBuilderImagePickerState extends State<FormBuilderImagePicker> {
110110
child: ListView(
111111
scrollDirection: Axis.horizontal,
112112
children: field.value.map<Widget>((item) {
113-
return Container(
114-
width: widget.imageWidth,
115-
height: widget.imageHeight,
116-
margin: widget.imageMargin,
117-
child: GestureDetector(
118-
child: item is String
119-
? Image.network(item, fit: BoxFit.cover)
120-
: Image.file(item, fit: BoxFit.cover),
121-
onLongPress: _readOnly
122-
? null
123-
: () {
124-
field.didChange(
125-
[...field.value]..remove(item));
126-
},
127-
),
113+
return Stack(
114+
alignment: Alignment.topRight,
115+
children: <Widget>[
116+
Container(
117+
width: widget.imageWidth,
118+
height: widget.imageHeight,
119+
margin: widget.imageMargin,
120+
child: item is String
121+
? Image.network(item, fit: BoxFit.cover)
122+
: Image.file(item, fit: BoxFit.cover),
123+
),
124+
if (!_readOnly)
125+
InkWell(
126+
onTap: () {
127+
field.didChange([...field.value]..remove(item));
128+
},
129+
child: Container(
130+
margin: EdgeInsets.all(3),
131+
decoration: BoxDecoration(
132+
color: Colors.grey.withOpacity(.7),
133+
shape: BoxShape.circle,
134+
),
135+
alignment: Alignment.center,
136+
height: 22,
137+
width: 22,
138+
child: Icon(
139+
Icons.close,
140+
size: 18,
141+
color: Colors.white,
142+
),
143+
),
144+
),
145+
],
128146
);
129147
}).toList()
130148
..add(

0 commit comments

Comments
 (0)