ibrahimAkkaya
ibrahimAkkaya

Reputation: 23

How to call a function on start in Flutter

I created new page in my app but i want to call function without set state

this is my function:

yaziGetir(Mahalle mahalle) {
    FirebaseFirestore.instance
        .collection("Mahalleler")
        .doc(mahalle.neighborhood)
        .get()
        .then((gelenVeri) {
      setState(() {
        gelenYaziBasligi = gelenVeri.data()['Eğitim'];
        gelenYaziIcerigi = gelenVeri.data()['Geri Dönüşüm'];
      });
    });
  }

Upvotes: 2

Views: 8149

Answers (2)

Tasnuva Tavasum oshin
Tasnuva Tavasum oshin

Reputation: 4750

InitState(){} ,where you can call your function

Upvotes: 0

Deepak Lohmod
Deepak Lohmod

Reputation: 2272

You should make the call of your function in initState rather then in widget tree as everytime the widget is rebuild, it will call the function to execute again and again(leading to more reads).

@override
void initState()
{
super.initState();
yourFunction();//call it over here
}

Upvotes: 5

Related Questions