I've implemented Cloud Firestore into my Flutter app and encountered this problem: if there's no network connection on the very first load of the app (after installation), no data is shown. My question is: How to make so that the data from Firestore is shown on the first load (after installation) even without internet connection? My code for fetching data is this:
class QuestionsListState extends State<QuestionsList> {
@override
Widget build(BuildContext context) {
return new StreamBuilder<QuerySnapshot>(
stream: _questionsCollectionReference
.where("category", isEqualTo: _chosenCategory).orderBy("order").snapshots,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) return const Text('');
final int messageCount = snapshot.data.documents.length;
return new ListView.builder(
itemCount: messageCount,
itemBuilder: (_, int index) {
final DocumentSnapshot document = snapshot.data.documents[index];
return new ListTile(
title: new FlatButton(
onPressed: () {
Navigator.push(context, new MaterialPageRoute(
builder: (BuildContext context) => new AddAnswerDialog(),
fullscreenDialog: true,
));
},
child: new Text(
document['text'],
style: new TextStyle(fontSize: 18.0, color: Colors.blue),
)),
);
},
);
},
);
}
}