Bug*_*Bug 4 future dart flutter
我正在构建一个使用 api 的应用程序,并且我正在使用 future 构建器来获取数据,但问题是当状态更改时它会重建,我想防止这种情况发生。
谢谢,
GJJ*_*GJJ 11
尝试使用这个:
class Example extends StatefulWidget {
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
Future<response> future;
@override
void initState() {
future = _asyncmethodCall();
super.initState();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: future,
builder: (context, snapshot) {
// create some layout here
},
);
}
Future<someResponse> _asyncmethodCall() async {
// async code here
}
}
Run Code Online (Sandbox Code Playgroud)
类似的问题:如何处理不需要的小部件构建?
| 归档时间: |
|
| 查看次数: |
2690 次 |
| 最近记录: |