I'm trying to implement a Slidable widget to delete a chosen document from a firestore snapshot. Here's my code:
return Expanded(
child: ListView(
children: snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic> data =
document.data()! as Map<String, dynamic>;
return Card(
color: const Color(0xff303437),
elevation: 0,
margin: const EdgeInsets.only(
top: 10,
bottom: 10,
right: 0,
left: 0,
),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Slidable(
endActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
key: ObjectKey(data['date']),
onPressed: deleteData,
backgroundColor: const Color(0xfffe4A49),
foregroundColor: Colors.white,
icon: Icons.delete,
label: 'Delete',
),
],
),
child: ListTile(
..
)
And for now the function deleteData only does this:
void deleteData(BuildContext context) {
debugPrint(context.widget.key.toString());
}
What I'm trying to accomplish is: use the document 'date' as key to delete it, but the debugPrint give me null every time. I'm sure data['date'] works because I can see each of them in the ListTile.
How can I pass the key to the deleteData function,so I can filter all the documents by timestamp and delete the correct one?