0

I am trying to fetch some data from firebase which is in this order :

+73bbm2guOygsfqddvqwTTOLRC3w1

   +-LY2t4PuMhDBPO0jAZ3f
        brand: 
        id: 
        model: 
        year:

I want the dropdown button to hold ids for all cars of that user

I have managed to retrieve the data as Map with this code :

static getUserCars() async {
  final response = await FirebaseDatabase.instance
    .reference()
    .child("cars")
    .child(uid)
    .once();
  print(response.value);
  Map map = json.decode(response.value);

  return map;
}

How can I show these values from the database in a DropDownButton?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Osama
  • 513
  • 2
  • 8
  • 18
  • It should be fairly similar to what is done here for Firestore: https://stackoverflow.com/questions/52823542/how-to-bind-a-firestore-documents-list-to-a-dropdown-menu-in-flutter, or here with just a raw JSON: https://stackoverflow.com/questions/46625438/flutter-populate-dropdownmenu-with-json – Frank van Puffelen Feb 09 '19 at 15:50
  • its a bit different retrieving data from firebase than firestorm and also I cannot change to firestorm now cause I already build lots and lots of functionality using firebase – Osama Feb 09 '19 at 17:00
  • I have managed to retrieve the data but I keep getting 2 errors : one is the Future is not subtype of string and the other error happens when I try to work around it it says int is not an instance of string – Osama Feb 09 '19 at 17:00
  • That sounds like you're making progress, so I'd update your question with the latest [MCVE](http://stackoverflow.com/help/mcve) of where you are stuck now. – Frank van Puffelen Feb 09 '19 at 18:24

1 Answers1

0

Here's an answer I've posted to a question similar to yours. What you can do here is to able to figure out how to fetch data from Firestore and map it to a List. There are many ways to fetch data from Firestore, in the sample I've provided, StreamBuilder is used.

Once you've done that, the data can be easily displayed on a Widget, like a DropdownButton.

Omatt
  • 8,564
  • 2
  • 42
  • 144