when I used Firestore query data stored in list variable but when I try to use this data outside the query it won't work. Please help me where I'm making mistake.
List<ContactsModelClass> _groupContactList1 ; //declare list variable
_groupCollection
.doc(widget.groupId)
.collection("groupContactList")
.get()
.then((docs) {
showLog('--->>>>>>${docs.docs.length}');
_groupContactList1 = List<ContactsModelClass>.generate(
docs.docs.length,
(index) => ContactsModelClass.fromJson(
docs.docs[index].data(),
),
); //Store data in list variable
print("init groupList:[${_groupContactList1.length}]"); //get data
});
print(
"groupContactList list data:[${_groupContactList1.length}]"); // can not access data which store above in code. why?