将
以下是我的代码,用于显示基于API调用的数据的列表视图
body:onAPICall
? AppWidget().spinner()
: propertyList.length == 0 ||
_IsSearching && searchList.length == 0
? Center(
child: Text(
'No Data',
style: TextStyle(
fontWeight: FontWeight.w600, fontSize: 20),
))
: ListView.builder(
itemCount: propertyList.length,
itemBuilder: (context, index) {
return propertyListData(index);
}),
这里onAPICall是一个布尔值。现在我可以显示列表视图或无数据正确
但我尝试在列表视图上方添加一个文本视图,如下所示
body: SafeArea(
child: Column(children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 15, left: 10, right: 10),
child: ListTile(
dense: true,
title: Text(_currentAddress,
textAlign: TextAlign.start,),
)),
isApiCall
? AppWidget().spinner()
: propertyList.length == 0 ||
_IsSearching && searchList.length == 0
? Center(
child: Text(
'No Related Properties',
style:
TextStyle(fontWeight: FontWeight.w600, fontSize: 20),
))
: ListView.builder(
itemCount: propertyList.length,
itemBuilder: (context, index) {
return propertyListData(index);
}),
]))
现在我只能看到Text和appwidget出现,但内容列表没有加载,如果没有数据,它会出现在页面顶部。
您必须确保ListView
有一个大小,因为Column
没有给它一个最小大小。要修复它,请将列表(和中心(包装在Expanded
中
ListView
的shrinkWrap
属性设置为true
。