我试图在flutter中从listView中删除图片,随机选择。没有指定图像的位置,我收到以下错误:
RangeError (index): Invalid value: Not in inclusive range 0..2: 3
我不会经常弄错,有时有时不会。根据选择照片的位置。照片从数据库中删除。
这是我使用的代码:
child: ListView.builder(
itemCount: filteredUsers.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContextcontext, int index) {
return InkWell(
child: Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 8.0, left: 8.0, right: 8.0),
child:
Container(
height: 140, width: 140,
child:
ClipRRect(
borderRadius:
BorderRadius.circular(8),
child:
AspectRatio(
aspectRatio:
1.2,
child:
Image.network(
filteredUsers[index].ImageURL.toString(),
width: double.infinity,
height: 400,
fit: BoxFit.cover,
),
),
))),
onTap: () {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
// title: Text("Alert Dialog Box"),
content: Text("delete..?".tr()),
actions: <Widget>[
TextButton(
onPressed: () {
setState(
() {
filteredUsers
.removeAt(
index);
deleteImage(filteredUsers[index].id);
Navigator.of(ctx).pop();
});
},
child: Text("OKdelete".tr()),
),
TextButton(
onPressed: () {
Navigator.of(ctx).pop();
},
child: Text("Closes".tr()),
),
],
),
);
}
);
},
),
void deleteImage(id) {
var url = "https://***************deleteImage.php";
http.post(Uri.parse(url), body: {
'id': id.toString(),
})