'is there a way to delete users from inside a flutter app from a firebase database

so I made an app that acts as an admin where the admin can add users, these users can then log into their account using the credentials(email and password set by the admin) the admin just assigned to them.

adding the user is working but not in the way it is intended to, but I couldn't find anything that will help me delete the user from the list(meaning deleting the user data as well as their respective credentials). the image here shows a list of the users added by the admin from the admin app I want a function that will allow me to delete user data as well as the credentials from the firebase database.

and if possible when the delete function is found I would love to get the function to add users with their credentials, because while my function works (it adds the users' credentials to the firebase and add the user data to the list and it doesn't redirect me to the account I just added) onPressed:() async{DocumentSnapshot data = await FirebaseFirestore.instance.collection("user").doc(FirebaseAuth.instance.currentUser!.uid).get(); print(data.get("name"))} returned the user I just added ex the user I just added using the admin account, even tho I'm logged into the admin account .

i know my English is messed up and I probably haven't explained this the right way but please for those willing to help feel free to ask any question u need

enter image description here

enter image description here

enter image description here



Solution 1:[1]

to delete a user from firebase, you can use this

Future<User> _getFirebaseUser() async {
    return FirebaseAuth.instance.currentUser;
  }


var user = await _getFirebaseUser();

    await user.delete();

to delete user data you can use:

  FirebaseFirestore.instance.collection('users').doc(user.uid).delete();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1