Home > Enterprise >  How to convert object to map in dart flutter
How to convert object to map in dart flutter

Time:12-18

using Stream I get the data from firebase

void getsds() async {
DatabaseReference ref =
    FirebaseDatabase.instance.ref("NearbyAccidents/User1/acc_coordinates");



Stream<DatabaseEvent> stream = ref.onValue;



stream.listen((DatabaseEvent event) {
  print('Event Type: ${event.type}'); // DatabaseEventType.value;

  print('Snapshot: ${event.snapshot.value}');

  List<Object?> map1 = event.snapshot.value as dynamic;

  print(map1[0]);

});

}

enter image description here

for printing map[0] I got this. but this is object. so I want to convert as map

How can covert this object to map

CodePudding user response:

Try this it will solve your problem

final mapCreated = Map.from(map1[0]);

CodePudding user response:

final mapCreated = Map.from(map1[0] as Map<Object?, Object?>);
  • Related