如何显示我的列表?(Dart & Flutter)



HIIII!我在需要显示项目的地方遇到了这个问题,但我做不到。我不知道该把FutureBuilder放在哪里。它应该在这里显示这个中心图像描述

Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Column(
children: [
HomeAppBar(),
PointShopInfo(),
Text(
"Items",
style: TextStyle(
fontFamily: 'Inter-bold',
fontSize: 23,
),
),
],
),
FutureBuilder(
future: _getRedeemShop(),
builder: (BuildContext context, AsyncSnapshot snapshot3) {
if (snapshot3.data == null) {
return Center(
child: Text(
"Nothing to see here...",
style: TextStyle(
color: Color.fromARGB(255, 150, 150, 150),
fontSize: 16,
fontFamily: 'Inter',
),
),
);
} else {
return ListView.builder(
itemCount: snapshot3.data.length,
itemBuilder: (BuildContext context, int index) {
PointShopData data = snapshot3.data[index];
return Card(
color: Colors.white,
margin:
EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: ListTile(
title: Text(
snapshot3.data[index].points_name,
style: TextStyle(
fontFamily: 'Inter-bold',
fontSize: 18,
),
),
subtitle: Text(
snapshot3.data[index].points.toString(),
style: TextStyle(
fontFamily: 'Inter-semibold',
fontSize: 12,
),
),
),
);
},
);
}
},
),
],
),
],
),
);
}

我试着把它和其他元素放在同一列,它看起来仍然像这里的中心图像描述

尝试这个

if (snapshot3.connectionState == ConnectionState.done && snapshot3.data == null) {
return Center(
child: Text(
"Nothing to see here...",
style: TextStyle(
color: Color.fromARGB(255, 150, 150, 150),
fontSize: 16,
fontFamily: 'Inter',
),
),
);
}

用于检查数据是否为空并成功连接,因此显示消息,否则将显示您的列表

如果这不起作用,你的调试会说什么?

最新更新