[英]How Can i get numbered list of items or texts in flutter within a container or a card?
嗨,我正在尝试在 flutter 中找到自己的方式,但无法在卡片或容器中获取编号列表,如下所示:
还有一个从右到左的列表,如果可能的话,把数字做成圆形设计。
如果您使用的是ListView.builder
,那么这很容易。
这是示例:
List<String> list =["first text", "second text", "third text"];
...
// Now you can render this list with numbering with ListView.builder easily.
ListView.builder
(
itemCount: list.length,
itemBuilder: (BuildContext ctxt, int index) {
return new Text(index.toString()+ "."+list[index]);
}
)
/*
PS: answering this from mobile so couldn't give you the whole example.
But I hope you got the general idea.
*/
为了让它在圆圈中呈现数字,而不是像我们在上面的示例中那样返回简单的 Text 小部件,我们需要返回具有两个子元素 CircleAvatar 和 Text 的 Row 小部件。
例子:
ListView.builder
(
itemCount: list.length,
itemBuilder: (BuildContext ctxt, int index) {
return Row( children: [
CircleAvatar(
child: Text(index.toString())
),
Text(list[index]),
);
}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.