You can skip FutureBuilder
and use initState
and load the List
as shown below :
List<String> webServiceList ;
List<String> localList = [ 'Foo' ,'Foo' , 'Foo' , 'Foo'] ;
@override
void initState() {
super.initState();
loadData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: webServiceList != null ? ListView.builder(
itemCount:webServiceList.length,
itemBuilder: (_ , index){
return Text(webServiceList[index]);
}) : ListView.builder(
itemCount:localList.length,
itemBuilder: (_ , index){
return Text(localList[index]);
}),
);
}
void loadData() async{
webServiceList = await ///Get data for web services API ;
setState(() {
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…