Look at my database structure:
and here is my code that I want to use ID in :
Widget build(BuildContext context) {
return SafeArea(
child: InkWell(
borderRadius: BorderRadius.circular(30),
child: Dismissible(
key: UniqueKey(),
direction: DismissDirection.startToEnd,
background: Container(
color: Colors.red,
child: Row(
children: [
Icon(Icons.delete),
Text(
'Move to trash',
style: TextStyle(
color: Colors.white,
fontFamily: 'Righteous',
),
)
],
),
),
confirmDismiss: (DismissDirection direction) async {
return await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Delete Confirmation"),
content: Text("Are you sure you want to delete this item?"),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text("Delete")),
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text("Cancel"),
),
],
);
});
},
onDismissed: (DismissDirection direction) async {
if (direction == DismissDirection.startToEnd) {
print('item deleted');
}
await deleteCar(
'wam4jSgeIpWHIBLVXvmv'); //I want to get doc ID to delete it
},
4
Answers
this line solve the problem :
but when you have 2 items have the same CarName you must add another where() to get specific id.
There is some way:
As you get it value.docs.first.id is what you need.
Not sure if I understand what you triying to achieve. But the way I see it, you can duplicate that id as an atribute of the element when you create it for example.
or when you map cars, use the key you got as an atribute of your Car Model. This is an example for products.
‘key’ is the value you want.
HAPPY CODING 🙂