Created
September 4, 2021 06:19
-
-
Save JaveedIshaq/9993daf97bf45badd34398da9126a9ea to your computer and use it in GitHub Desktop.
Get Flutter FireStore Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cloud_firestore/cloud_firestore.dart'; | |
import 'package:flutter/material.dart'; | |
class DisplayCollection extends StatefulWidget { | |
@override | |
_DisplayCollectionState createState() => _DisplayCollectionState(); | |
} | |
class _DisplayCollectionState extends State<DisplayCollection> { | |
final Ref = Firestore.instance.collection("Countries"); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Collection-Countries from Firebase"), | |
), | |
body: Column( | |
children: <Widget>[ | |
StreamBuilder( | |
stream: Ref.snapshots(), | |
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) { | |
if (snapshot.hasData) { | |
return Container( | |
height: 600, | |
child: ListView.builder( | |
itemCount: snapshot.data.documents.length, | |
itemBuilder: (context, index) { | |
return Container( | |
height: 100, | |
child: Card( | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
Text( | |
snapshot.data.documents[index] | |
.data['CountryName'], | |
style: TextStyle( | |
fontSize: 25, | |
fontWeight: FontWeight.bold), | |
), | |
Text( | |
snapshot.data.documents[index] | |
.data['CapitalName'], | |
style: TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.w700), | |
), | |
], | |
), | |
), | |
); | |
}), | |
); | |
} else if (snapshot.hasError) { | |
return Text(snapshot.error.toString()); | |
} else { | |
return CircularProgressIndicator(); | |
} | |
}, | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment