简体   繁体   中英

Deleting a child from Realtime database using Flutter

I create a Realtime database and push data on it. I need to delete a specific child but I couldn't because I don't know the random key which firebase generate for children how could I access specific child in order to delete it in Flutter. 此图像代表实时数据库结构

to get the child key you need to take a DataSnapshot then you can order the key

snapshot.key.toString()

It will return all keys of the Realtime Database in the current level.

If you need to get an specific key you should link it with index of the user choice.

FirebaseAnimatedList(
              shrinkWrap: true,
              query: FirebaseDatabase.instance.ref().child('journeys'),
              itemBuilder: (BuildContext context, DataSnapshot snapshot,
                  Animation animation, int index) {
                try {
                  return Text(snapshot.key.toString());
                } catch (e) {
                  customSnackBar(context, e.toString(), 3, Colors.white24, Colors.brown, 17);
                }
              }),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM