Reputation: 955
When I click on the icon, the fields of the news that was clicked are added to the database:
final _fireStore = FirebaseFirestore.instance;
IconButton(onPressed: () async {
newsController.addNews(article);
_fireStore.collection('favoriteItems').add({
'name' : article.source.name,
'title': article.title,
'image': article.urlToImage,
});
},
icon: const Icon(Icons.bookmark_border)),
How now, when clicking on another icon, you can delete these values from the database?
IconButton(onPressed: () {
},
icon: const Icon(Icons.bookmark_remove))
Upvotes: 0
Views: 53
Reputation: 49
First, get your ID
Then, Write this Lines:
IconButton(onPressed: () {
CollectionReference users = FirebaseFirestore.instance.collection('favoriteItems');
Future<void> deleteItems() {
return users
.doc('itemsID')
.delete()
.then((value) => print("Items Deleted"))
.catchError((error) => print("Failed to delete Item: $error"));
}
}, icon: const Icon(Icons.bookmark_remove))
Upvotes: 1