Reputation: 2383
So in my app, I am building a list of widgets, which is basically just a container with text in it. I am doing this for a variety of reasons, but basically here is where I am having the problem.
I can view this list in a ListView.Builder, but I do not want to view them that way. I want to be able to view them in a container. Then wrap down the container as items get added.
Below is a mock up of what I am trying to do.
Right now my page looks like this.
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,
);
},
)
))]),
And the Tag Widget adds to the list with the following.
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);
});
}
}
Adding the list to a listview, I can do, but it is not the desired affect.
I have no clue how to do what I am looking for and I am completely lost.
Upvotes: 0
Views: 5005
Reputation: 627
Try and add shrinkWrap to the ListView Builder
child: ListView.builder(shrinkWrap:true, <-- this
.... # then continue your logic
Upvotes: 1