Skip to main content

Retrieve Data from Firebase in Flutter


Retrieving Data Using DocumentSnapshot

Retrieve Data Stored in a map in firebase

First, Add dependencies:
dependencies:
  cloud_firestore: ^1.0.7
Now, run an implicitdart pub get.
Note: Install the latest version.
Import it
Now in your Dart code, you can use:
import 'package:cloud_firestore/cloud_firestore.dart';
Now in your Dart code:
DocumentSnapshot documentSnapshot = await FirebaseFirestore.instance.collection('Collection_Name').doc('Document_Id').get();
Also, to get data length use:
int dataLength = documentSnapshot.data().length;
To get data of a single map:
List<String> dataList = documentSnapshot['key'].toString();
For queries or any other help related to flutter or dart feel free to ask in the comments😊

Comments