I'm experiencing interesting behavior. I have a FutureBuilder in Stateful widget. If I return FutureBuilder alone, everything is ok. My API gets called only once.
However, if I put extra logic, and make a choice between two widgets - I can see in chrome my API gets called tens of times. I know that build
method executes at any time, but how does that extra logic completely breaks Future's behavior?
Here is example of api calling once.
@override
Widget build(BuildContext context) {
return FutureBuilder(..);
}
Here is example of api being called multiple times if someBooleanFlag
is false
.
@override
Widget build(BuildContext context) {
if(someBooleanFlag){
return Text('Hello World');
}
else{
return FutureBuilder(..);
}
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…