Panda Power
Panda Power

Reputation: 335

flutter adjust width of ListView children

I am trying to create a chat history like this

enter image description here

Tried with ListView and CustomerScrollView both force the child to take the full horizontal width.

Also tried to nest a fixed size container inside a ListView Child, still display as full length.

How can I achieve this?

Code - where Child Container is a fixed size but forced to take up the whole width of screen.

child: ListView(
          shrinkWrap: true,
          children: <Widget>[
            Container(
              color: Colors.red,
              width: 20,
              height: 40,
            ),
          ],
        ),

Upvotes: 2

Views: 5430

Answers (1)

Swift
Swift

Reputation: 3410

Try adding a padding or margin to your container:

Container(
  padding: EdgeInsets.only(right: 10),
  // OR
  margin: EdgeInsets.only(right: 10),
);

Use EdgeInsets.only(left: 10) for the opposite.

Upvotes: 9

Related Questions