'flutter firebase reading too much

I have a total of 4 documents in two different collections... As you can see below, I want to call these documents only once when the application starts... But my firestore usage is suddenly 50-60 for reading... Help please..Hello guys ,I have a total of 4 documents in two different collections... As you can see below, I want to call these documents only once when the application starts... But my firestore usage is suddenly 50-60 for reading... Help please..Hello guys ,I have a total of 4 documents in two different collections... As you can see below, I want to call these documents only once when the application starts... But my firestore usage is suddenly 50-60 for reading... Help please..

  myclubs({Key? key}) : super(key: key);

  bool get wantKeepAlive => true;
  late CollectionReference users;
  late Object kullaniciAdi;
  final Future<FirebaseApp> _future = Firebase.initializeApp();
  @override
  void initState() {}

  var collectionn = FirebaseFirestore.instance.collection('clubs_takipci_log');
  var collectionn1 = FirebaseFirestore.instance.collection('clubs');

  List item = [];

  late SharedPreferences sharedPrefs;
  Future<Object> _getPrefs() async {
    sharedPrefs = await SharedPreferences.getInstance();
    kullaniciAdi = sharedPrefs.getString('kullanici_adi') ?? 0;
    return kullaniciAdi;
  }

  List item2 = [];

  Future<void> loadClubs(data) async {
    //collectionn1.where('age', isGreaterThan: 20).get().then((value) => null);
    await data["clubs"].Future.forEach((k, v) async {
      if (v == 1) {
        print(k);

        collectionn1.doc(k).get().then((value) {
          print(value["kulup-adi"]);
          return item2.add(value["kulup-adi"]);
        });
      } else {}
    });
  }

  getBuyerList() async {
    await FirebaseFirestore.instance
        .collection('clubs')
        .where('okul', isEqualTo: "gtu")
        //.orderBy("dislike-count")
        .get()
        .then((QuerySnapshot querySnapshot) {
      querySnapshot.docs.forEach((doc) {
        print(doc["kulup-adi"]);
        item2.add(doc["kulup-adi"]);
      });
    });
  }

  int trophyPoint = 1;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: FutureBuilder(
            future: _getPrefs(),
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                print("Future2");

                return FutureBuilder<DocumentSnapshot>(
                  future: collectionn.doc(kullaniciAdi.toString()).get(),
                  builder: (BuildContext context,
                      AsyncSnapshot<DocumentSnapshot> snapshot) {
                    if (snapshot.hasError) {
                      return Text("Something went wrong");
                    }

                    if (snapshot.hasData && !snapshot.data!.exists) {
                      return Text("Document does not exist");
                    }

                    if (snapshot.connectionState == ConnectionState.done) {
                      // loadClubs(snapshot.data!.data() as Map<String, dynamic>);

                      return FutureBuilder(
                        future: getBuyerList(),
                        builder: (BuildContext context, snapshot) {
                          if (snapshot.hasError) {
                            return Text("Something went wrong");
                          }

                          if (snapshot.connectionState ==
                              ConnectionState.done) {
                            // loadClubs(snapshot.data!.data() as Map<String, dynamic>);

                            print("son");
                            return Text(
                              "data" + item2[0],
                              style: TextStyle(color: Colors.black),
                            );
                          }

                          return Center(child: CircularProgressIndicator());
                        },
                      );
                    }

                    return Center(child: CircularProgressIndicator());
                  },
                );
              } else {
                return Center(child: CircularProgressIndicator());
              }
            }));
  }
}```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source