2021年1月21日星期四

Reading data from user in realtime database (Google Database) and creating a Map() from DataSnapshot

I'm attempting to create a map from the data that I get from the user in Realtime database. I manage to get the data from the user. What I'm attempting to perform is, the button data from EACH user is going to be stored in the database. This is how the buttons are saved for now: enter image description here

The buttons can have different names, but the content inside will always be called icon and nome.

This is the code I'm using to get the data and transform into a Map(), which isn't working:

void readData()async{      Map<dynamic, dynamic> button_list = Map();        final FirebaseUser user = await _auth.currentUser();        databaseReference.child(user.uid+"/buttons/").once().then((DataSnapshot snapshot) {        button_list = snapshot.value;      });      button_list.values.toList()[index]; //index doesn't work        print(button_list);    }  ```<br><br>  I think I will need an index for each button, for the StreamBuilder to create each button.<br>  I will be using this code later on inside a StreamBuilder, so whenever the is a new button, I will redo the main page and create that button on screen. **I will use the Map to create the buttons in the StreamBuilder (like a for loop).**  
https://stackoverflow.com/questions/65838201/reading-data-from-user-in-realtime-database-google-database-and-creating-a-map January 22, 2021 at 09:37AM

没有评论:

发表评论