[英]Flutter How to Display a List of Widgets in a Container
因此,在我的應用中,我正在構建一個小部件列表,該列表基本上只是一個包含文本的容器。 我這樣做有多種原因,但基本上這是我遇到問題的地方。
我可以在ListView.Builder中查看此列表,但是我不想那樣查看它們。 我希望能夠在容器中查看它們。 然后在添加項目時包裝好容器。
以下是我正在嘗試做的模擬。
現在我的頁面看起來像這樣。
body: Column(children: <Widget>[
Expanded(
flex: 3,
child: Container(
width: MediaQuery.of(context).size.width*0.8,
child: Row(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: hashList.length,
itemBuilder: (context, index){
return Container(
child: hashList[index],
);
}),
)
],
),
),
),
Expanded(
flex: 6,
child: Container(
color: Colors.black,
child: ListView.builder(
itemCount: snapshot.length,
itemBuilder: (context, index) {
return Tag(
callback: (list) => setState(() => hashList = list),
tag: snapshot[index].data["title"],
list: hashList,
id: index,
);
},
)
))]),
Tag Widget將添加以下內容。
void _handleOnPressed() {
setState(() {
isSelected = !isSelected;
isSelected
? _animationController.forward()
: _animationController.reverse();
isSelected ? widget.list.add(
Container(
padding: EdgeInsets.all(10),
height: 45,
child: Text(widget.tag, style: TextStyle(color: Color(0xffff9900), fontSize: 20, fontFamily: 'Dokyo'),),
decoration: BoxDecoration(
border: Border.all(color: Color(0xffff9900),),
borderRadius: BorderRadius.circular(10))
)): widget.list.removeAt(widget.id);
});
}
}
我可以將列表添加到列表視圖中,但這不是所需的效果。
我不知道該怎么做,我完全迷路了。
嘗試將rinkleWrap添加到ListView Builder
child: ListView.builder(shrinkWrap:true, <-- this
.... # then continue your logic
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.