flutter flutter Listview -> Container 'width' not working ?
/example/ ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
scaffold
body : ListView
children : [
Container (
width: 100, // Not Working
height: 100, // Ok
color: Colors.red.
),
]
!!! but !!!
scaffold
body : ListView
children : [
Stack(
children : [
Container (
width: 100, // OK
height: 100, // Ok
color: Colors.red.
),
]
why ??

Try below code, Wrap your Container inside UnconstrainedBox()
Refer UnconstrainedBox
Refer Layout Constraints
ListView(
shrinkWrap: true,
children: [
UnconstrainedBox(
child: Container(
width: 100, // OK
height: 100, // OK
color: Colors.red,
),
)
],
),
Your result-> 
Below Code Also will work. we can also use Align Widget.
ListView(
shrinkWrap: true,
children: [
Align(
alignment: Alignment.topLeft,
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
)
],
)
Also check how constrain works in flutter.https://docs.flutter.dev/development/ui/layout/constraints
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With