如何在flutter中构建小部件之前加载/填充对象



我有一个消息选项窗口来显示可用于聊天的用户,我在其中加载一个列表,并在initstate((中填写。我可以看到数据被填充到调试器中,但并没有在第一时间显示出来。当我做热重新加载它的工作?我在这里错过了什么?

class _ChatwindowState extends State<Chatwindow> { List<ChatUsers> chatwithPeople=[]; 
@override void initState(){  super.initState();  setState(() { this.chatwithPeople=peopletomessage(); });}
@override void dispose() { super.dispose(); }
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Messages'),),
body:databindUsers(context,widget.currentUser,this.chatwithPeople)
);
}

像一样使用FutureBuilder

FutureBuilder(
future: peopletomessage(),//it will return the future type result
builder: (context, snapshot) {

if(snapshot.connectionState == ConnectionState.done) {
return databindUsers(context,widget.currentUser,this.chatwithPeople);
}
return _progress(); //show loading
})

最新更新