Last active
March 28, 2022 01:14
-
-
Save trunghq3101/025199fc4921d1d2c620cd241ea00c13 to your computer and use it in GitHub Desktop.
Make item content wrapped vertically inside a horizontal ListView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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