我有一个列表视图,其中充满了作为聊天信息的FireBase集合。
当用户长按一个ListTile(列表中的一个项目)时,我会显示一个底页。
当用户单击
Delete
按钮,文件应该被删除。单击“删除”按钮后,无法找到删除所选文档的方法。
ListView小部件:
return ListView.builder(
padding: new EdgeInsets.all(8.0),
reverse: true,
itemCount: snapshot.data.documents.length,
itemBuilder: (_, int index) {
var message = snapshot.data.documents[index]["content"];
var from = snapshot.data.documents[index]["idFrom"];
return new ListTile(
leading: new CircleAvatar(
backgroundColor: Colors.blue,
child: new Image.network(
"http://res.cloudinary.com/kennyy/image/upload/v1531317427/avatar_z1rc6f.png")),
title: new Row(
children: <Widget>[
new Expanded(child: new Text(message))
]
),
subtitle: new Text(from),
onLongPress: () {
showModalBottomSheet<void>(context: context,
builder: (BuildContext context) {
return Container(
child: new Wrap(
children: <Widget>[
new ListTile(
leading: new Icon(Icons.delete),
title: new Text('Delete'),
onTap: () =>
// Remove the tapped document here - how?
print(snapshot.data.documents[index]["id"])
Firestore.instance.collection("chats").document("ROOM_1")
.collection("messages").document(snapshot.data.documents[index]["id"])
.delete();
)
)
]
)
);
});
}
);
});
我需要找到一种方法来删除
onTap()
方法。不知道为什么,但即使我这样做了:
onTap: () => {
// Remove the tapped document here - how?
const id = snapshot.data.documents[index]["id"];
},
IDE重试错误
Expected an identifier