当我使用未来的构建器扩展图块时,我正在尝试调用api。哪个返回一个列表。但是,当我单击它时,它会扩展整个屏幕,并且不显示任何内容。
代码如下:
Widget build(BuildContext context) {
return FutureBuilder(
future: marketApiCall(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if(snapshot.hasData) {
return ListView.separated(
shrinkWrap: true,
separatorBuilder: (BuildContext context, int index) => Divider(),
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int count) {
return ExpansionTile(
title: Text(snapshot.data[count].itemName),
children: <Widget>[
FutureBuilder(
future: getItemDetail(itemName: snapshot.data[count].urlName),
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
if(snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData){
debug.output(fromFunction:"Widget build", message: snapshot.data[0]['en']['description']);
return Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.8,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Item description: ", style: TextStyle(fontWeight: FontWeight.bold)),
Expanded(
child: Text(snapshot.data[0]['en']['description'].toString().replaceAll(reg, ''))
)
],
)
],
)
);
} else {
return Center(
child: Text("Error: No data")
);
}
} else {
return Center(
child: CircularProgressIndicator(),
);
}
}
)
],
);
},
);
} else {
return ListTile(
title: Text("There was an error with the api call, please try again later")
);
}
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
);
我尝试添加收缩包装,看是否可行。那不是。 另外,debug.output只是显示打印消息的自定义函数,因此无需担心。如您所见,它是futurebuilder中的一个Future Builder。我尝试将内部的将来构建器分离到一个单独的有状态类,然后将一列返回到扩展图块,但是那也不起作用。
答案 0 :(得分:1)
我认为问题出在“ FutureBuilder”之后
# m = imaplib.IMAP4_SSL(server) # useless
m = connect(server, user, password)
downloadAttachmentsInEmail(m, emailid, outputdir)
您要为其子容器提供80%的屏幕高度,以ExpansionTile的高度,它将占据整个屏幕(或几乎占据整个屏幕)。 尝试删除容器的高度,并让其子容器调整大小。