How to delete a specific user in a list from firebase in flutter

Viewed 20

I have a ListView of users I can add to a list in my flutter web app, each having a trash bin icon next to their name. How can I delete a specific user when I click on their trash bin icon?

Like the image below, how can I delete the CarCharm user from the list. Users do have their userID stored in firebase when they were created, but I do not know how to access that based on who I want to delete

enter image description here

1 Answers

1 . First, you have to store the data in a list of a user model

2 . you have to render the users from the list in for loop

note: for loop to render widget no need to add {}

Column(
 children: [
   for(var user in usersList)
    widget to show the users
 ]
)

and when you add this code you have to see the items in your app

NICE

then you have to add onPress for the delete button

the onPress function will be like this

onPress() => usersList.remove(user);

userList = the list that contains the users that come from firebase user = the single element in the for loop

then you have to add func to update the list in the firebase with the new list

I hope this will help you

Related