This is how I get data using stream builder from firebase
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('profile').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if (!snapshot.hasData) return const Text('Loading...');
final int messageCount = snapshot.data.documents.length;
return ListView.builder(
shrinkWrap: true,
itemCount: messageCount,
itemBuilder: (_, int index) {
final DocumentSnapshot document = snapshot.data.documents[index];
return Container();}
);
},
),
My question is, How to get a collection list data to a list inside initstate()
maybe using a function
List data=new List();
@override
void initState() {
super.initState();
//here
}