Skip to content

Instantly share code, notes, and snippets.

@trunghq3101
Last active March 28, 2022 01:14
Show Gist options
  • Select an option

  • Save trunghq3101/025199fc4921d1d2c620cd241ea00c13 to your computer and use it in GitHub Desktop.

Select an option

Save trunghq3101/025199fc4921d1d2c620cd241ea00c13 to your computer and use it in GitHub Desktop.
Make item content wrapped vertically inside a horizontal ListView
// ListView applies a tight constraint (minHeight = maxHeight in this case) to its children.
// So all children are forced to have the same height. To let an item to have its own size,
// first, remove constraints by using UnconstrainedBox.
// then, apply new loosen constraints with ConstrainedBox.
// Using only UnconstrainedBox would be sufficient in this specific case,
// but it can cause errors in case the child want to be as big as possible.
// So ConstrainedBox is needed to provide a specific constraints.
ListView(
scrollDirection: Axis.horizontal,
children: [
UnconstrainedBox(
child: ConstrainedBox(
constraints: BoxConstraints.loose(Size(160, 250)),
child: Column(
children: [
Container(
width: 160.0,
height: 200,
color: Colors.red,
),
],
),
),
),
],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment