Here’s a basic example of how to get data from Firestore Database:

Firestore database :

Firestore database

To get data only one-time :

FutureBuilder<QuerySnapshot>(
 future: FirebaseFirestore.instance.collection('Users').get(),
 builder:
     (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
   if (snapshot.hasError) {
     return const Text('Something went wrong');
   }

   if (snapshot.connectionState == ConnectionState.waiting) {
     return const Text("Loading");
   }

   return ListView.builder(
     itemCount: snapshot.data?.docs.length,
     itemBuilder: (context, index) {
       final data = snapshot.data?.docs[index];
       return ListTile(
         title: Text(data?['name'] ?? ''),
         subtitle: Text(data?['email'] ?? ''),
         trailing: Text(data?['dob'] ?? ''),
       );
     },
   );
 },
)

To get real time data :

StreamBuilder(
 stream: FirebaseFirestore.instance.collection('Users').snapshots(),
 builder:
     (BuildContext context, AsyncSnapshot snapshot) {
   if (snapshot.hasError) {
     return const Text('Something went wrong');
   }

   if (snapshot.connectionState == ConnectionState.waiting) {
     return const Text("Loading");
   }

   return ListView.builder(
     itemCount: snapshot.data?.docs.length,
     itemBuilder: (context, index) {
       final data = snapshot.data?.docs[index];
       return ListTile(
         title: Text(data?['name'] ?? ''),
         subtitle: Text(data?['email'] ?? ''),
         trailing: Text(data?['dob'] ?? ''),
       );
     },
   );
 },
)

Support On Demand!

Flutter