Answers for "how to return single document from firebase flutter"

0

how to return single document from firebase flutter

var collection = FirebaseFirestore.instance.collection('users');
var docSnapshot = await collection.doc('doc_id').get();
if (docSnapshot.exists) {
  Map<String, dynamic>? data = docSnapshot.data();
  var value = data?['some_field']; // <-- The value you want to retrieve. 
  // Call setState if needed.
}
Posted by: Guest on December-11-2021
0

how to return single document from firebase flutter

FutureBuilder<DocumentSnapshot<Map<String, dynamic>>>(
  future: collection.doc('doc_id').get(),
  builder: (_, snapshot) {
    if (snapshot.hasError) return Text ('Error = ${snapshot.error}');

    if (snapshot.hasData) {
      var data = snapshot.data!.data();
      var value = data!['some_field']; // <-- Your value
      return Text('Value = $value');
    }

    return Center(child: CircularProgressIndicator());
  },
)
Posted by: Guest on January-24-2022
0

how to return single document from firebase flutter

StreamBuilder<DocumentSnapshot<Map<String, dynamic>>>(
  stream: collection.doc('doc_id').snapshots(),
  builder: (_, snapshot) {
    if (snapshot.hasError) return Text('Error = ${snapshot.error}');

    if (snapshot.hasData) {
      var output = snapshot.data!.data();
      var value = output!['some_field']; // <-- Your value
      return Text('Value = $value');
    }

    return Center(child: CircularProgressIndicator());
  },
)
Posted by: Guest on January-24-2022

Code answers related to "how to return single document from firebase flutter"

Browse Popular Code Answers by Language