[英]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.