flutter - 网络调用后如何修改 UI 以填充子小部件
问题描述
我对颤动相当陌生,请帮助我在执行网络呼叫后如何填充儿童小部件?
类 _BusResultScreenState 扩展状态 {
@override 小部件构建(BuildContext 上下文){
helper myHelper = new helper();
myHelper.fetch(apiArg).then ((response) {
if(response['type']=="success") {
// Sample data from server in response.feedback
[
{"name":"bus1","id":"54"},
{"name":"bus2","id":"55"},
{"name":"bus3","id":"56"}
]
while(){
SharedBusCard(arg1,arg2,...) // This has to go into children Widget
}
}
});
return Scaffold(
backgroundColor: Colors.grey.shade200,
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
children: <Widget>[
Material(
elevation: 4,
child: Container(
... code
.... code
SizedBox(height: 15),
Expanded(
child: Container(
width: double.infinity,
height: double.infinity,
child: ListView(
children: <Widget>[
//I wanted to display results here
SharedBusCard(arg1,arg2,...) // this is the card to be looped
],
),
),
)
],
),
),
),
);
} }
谢谢你的帮助。
解决方案
使用FutureBuilder
小部件。这对网络调用很有用,您可以处理错误,在其中显示加载屏幕。这是文档和使用它的精彩视频。
推荐阅读
- javascript - Angular - 从服务发送请求比从组件发送请求更好?
- java - Spring Boot 1.5.20.RELEASE 上的 ErrorViewResolver 内无法重定向视图
- json - 如何将 json 内容写入 csv 文件?
- datatables - 如何将我的 BI 工具连接到 YouTube API (ODBC)?
- javascript - 我可以在客户端代码中更改 URL / 重定向的可能方法是什么?
- intellij-idea - Intellij Idea Refactoring - 如何让多个类扩展一个基类?
- python - 函数参数默认值的 Python 风格指南
- c - 如何编写ac程序来创建文件?
- javascript - Scrollmagic 不起作用 - 我该如何解决这个问题?
- javascript - 如何在反应中为直通点击事件添加颜色?(不改变字体颜色)