[英]How to display a list of items inside a column using a ListTile in Flutter
staff.ulogin is a list returned from a web service. staff.ulogin 是从 web 服务返回的列表。 If there is more than one item returned, I need to display of list of those items (displaying the company name).
如果退回的物品不止一件,我需要显示这些物品的列表(显示公司名称)。 I can get the first item displaying, but I'm not sure how to display the entire list.
我可以显示第一个项目,但我不确定如何显示整个列表。
I also need the user to be able to tap an item so I can setup that company for use, so I'll need to know what item they chose.我还需要用户能够点击一个项目,以便我可以设置该公司以供使用,所以我需要知道他们选择了什么项目。 Thanks for any help.
谢谢你的帮助。
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
I believe that the correct way of display a list o items is using a ListView.我相信显示项目列表的正确方法是使用 ListView。 For this case you can use a ListView.builder like this:
对于这种情况,您可以像这样使用 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.