I have the following code:
ExpansionTile(
maintainState: true,
children: [
FutureBuilder(
future: _future,
builder: ...
)
]
)
The default behavior is building all the widgets together. I would like to first build the ExpansionTile
, and then, on ExpansionTile
expanded, build the FutureBuilder
calling _future
.
2
Answers
In my thinking the FutureBuilder is very dumb Widget as it rebuild it self on every state change.
Still, i found a work around for your issue.
you refer to the below code:
Here i have taken a dynamic variable ‘futureFun’ that will have null or the future function itself and given to the FutureBuilder future property(FutureBuilder don’t build itself if you pass null to the future property).
Firstly, it will be null then if you expand the expansionTile it will be assigned with the future function, and after the performing your operations in the futureBuilder you can make it null so it doesn’t rebuild on every setState.
You can, pseudo code that goes along with your code