Ad

FutureBuilder Widget Returns Instance Of 'DataSnapshot' Only With Firebase RealtimeDatabase

- 1 answer

I unable to use FutureBuilder and StreamBuilder widgets with Firebase RealTimeDatabase i tried many time to retrieve the data in my RealTimeDatabase every time it returns in debug print

ConnectionState.done value is Instance of 'DataSnapshot',

      FutureBuilder(
      initialData: 1,
      future: FirebaseDatabase.instance.reference().child('hello').once(),
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        print(snapshot);
        return Text(snapshot.data.toString());
      },
    ),
Ad

Answer

Your getting the instance of the data snapshot so just add, .value.

 FutureBuilder(
  initialData: 1,
  future: FirebaseDatabase.instance.reference().child('hello').once(),
  builder: (BuildContext context, AsyncSnapshot snapshot) {
    print(snapshot);
    return Text(snapshot.data.value.toString());//just add value here
  },
),
Ad
source: stackoverflow.com
Ad