[英]How to display a list of items inside a column using a ListTile in Flutter
staff.ulogin 是从 web 服务返回的列表。 如果退回的物品不止一件,我需要显示这些物品的列表(显示公司名称)。 我可以显示第一个项目,但我不确定如何显示整个列表。
我还需要用户能够点击一个项目,以便我可以设置该公司以供使用,所以我需要知道他们选择了什么项目。 谢谢你的帮助。
if (staff.ulogin.length > 1) {
Alert(
context: context,
title: 'Choose Company',
content: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//how to display all the items
ListTile(
title: Text(staff.ulogin[0].company),
onTap () {}, // <--- how to get the index of the item tapped
),
],
),
),
buttons: [
DialogButton(
child: Text('Cancel', style: TextStyle(color: Colors.white, fontSize: 20)),
color: kMainColor,
onPressed: () {
Navigator.of(context).pop();
},
),
],
).show();
} else
我相信显示项目列表的正确方法是使用 ListView。 对于这种情况,您可以像这样使用 ListView.builder:
Container(
height: 300.0, // Change as you wish
width: 300.0, // Change as you wish
child: ListView.builder
(
itemCount: staff.ulogin.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(staff.ulogin[index].company),
onTap () {
someFunction(staff.ulogin[index]);
},
),
}
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.