toly-flutter / flutter_journey

25 stars 2 forks source link

+ 0006 怎么防止FutureBuilder过度刷新? #9

Open lp7799 opened 4 years ago

lp7799 commented 4 years ago

怎么防止FutureBuilder过度刷新当前页面,进入当前页面后 在页面setState操作后 会再次刷新FutureBuilder

lp7799 commented 4 years ago

在StatefulWidget中的状态管理中setState会刷新build状态会再次刷新FutureBuilder,建议在initState中构建futurebuild或者 State.didUpdateConfig或State.didChangeDependencies中。https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html 参考 The future must have been obtained earlier, e.g. during State.initState, State.didUpdateConfig, or State.didChangeDependencies. It must not be created during the State.build or StatelessWidget.build method call when constructing the FutureBuilder. If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted.

toly1994328 commented 4 years ago

在StatefulWidget中的状态管理中setState会刷新build状态会再次刷新FutureBuilder,建议在initState中构建futurebuild或者 State.didUpdateConfig或State.didChangeDependencies中。https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html 参考


image