Flutter 如何在小部件构建之前加载/填充对象?
我有一个消息选项窗口来显示可用于聊天的用户,在这里我加载一个列表,并在initstate()中填写。我可以看到数据在调试器中被填充,但在第一次时并没有显示出来。当我做热装时,它能工作吗?我错过了什么Flutter 如何在小部件构建之前加载/填充对象?,flutter,dart,Flutter,Dart,我有一个消息选项窗口来显示可用于聊天的用户,在这里我加载一个列表,并在initstate()中填写。我可以看到数据在调试器中被填充,但在第一次时并没有显示出来。当我做热装时,它能工作吗?我错过了什么 class _ChatwindowState extends State<Chatwindow> { List<ChatUsers> chatwithPeople=[]; @override void initState(){ super.initState(); se
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)
);
}
class_chatWindowsState扩展状态{List chatwithPeople=[];
@重写void initState(){super.initState();setState((){this.chatwithPeople=peopletomessage();});}
@重写void dispose(){super.dispose();}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(标题:文本('Messages'),),
正文:DataIndusers(上下文,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
})