I'm working on a project for a logistics warehouse. The idea is that I use Cloud Firestore for store pallets in a rack and that I can find it back in the system.
I can see my pallets in the app and it works well. Cloud Firestore has a read amount of 50.000 reads per day. If I start up the app it calculates the number of documents in the list and I can see it in the usage tab. That's okay but even if I do nothing in the app, the number increases.
Is there a solution to read the data only if the flutter page opens?
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class overzicht extends StatefulWidget {
@override
_overzichtState createState() => _overzichtState();
}
class _overzichtState extends State<overzicht> {
Future _data;
Future getPosts() async{
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore.collection("locaties").getDocuments();
return qn.documents;
}
@override
void initState() {
super.initState();
_data = getPosts();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Center(child: Text('Overzicht')),backgroundColor: Color.fromRGBO(17, 32, 42, 1),),
body: Container(
child: FutureBuilder(
future: _data,
builder: (_, snapshot) {
if(snapshot.connectionState == ConnectionState.waiting){
return Center(
child: Text('Loading...'),
);
} else{
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index){
return ListTile(
title: Text(snapshot.data[index].data["location"]),
);
});
}
}),
),
);
}
}