Flutter how i can use a setState event without refresh my futurebuilder

134

You can use this little trick. For example, this is your future:

Future<void> yourFuture async{
// do something
}

Use a final temp variable to store your future like this:

final temp = yourFuture;

Then use it in your FutureBuilder:

FutureBuilder(
future: temp,
builder: (context, snapshot){}
),
Share:
134
Admin
Author by

Admin

Updated on January 01, 2023

Comments

  • Admin
    Admin over 1 year

    I have a question.

    At the moment i try to build a category list with data from firebase.

    To load the data i use a futurebuilder.

    Here my category list:

    enter image description here

    Now i want to implement a color change event if i click on a list element. For example, if i click on tree the element tree should change the color.

    My problem:

    I create a object for every category. If i try to change the color i use in futurebuilder a setState. The setState refresh my Object. How i can use a setState without reload my the futurebuilder?

    Many thx (:

  • Admin
    Admin over 2 years
    Greate, many thx :D It's working. You saved my day
  • Trần Trung Hiếu
    Trần Trung Hiếu over 2 years
    Hehehe, no problem !