I want to fetch a simple document from firebase and store it in a map as soon as the screen loads, I'm trying to do this through the init state, i.e. calling the fetching function in the init state, but my map is still null. Here is some code :
Map<String, int> minDelivery;
void minimumDelivery() async{
await FirebaseFirestore.instance
.collection("minimumDelivery")
.limit(1)
.get()
.then((QuerySnapshot qs) {
qs.docs.forEach((doc) {
int amount = doc["min_amount"];
int charge = doc["charge"];
minDelivery = {
"amount":amount,
"charge":charge
};
});
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
minimumDelivery();
}
But the map is null when I am trying to access its data. I don't see where the problem is.I just want the map to have the required data at the start of screen.