Flutter - Using Fixed Width Widgets Inside ListView
ListView is used to display scrollable list of widgets. Children inside ListView takes whole width of ListView by default. So elements inside ListView expands to take whole width. There are couple of ways we can set fixed width to elements inside ListView.
- Using Align - Set alignment property of the Align widget to Alignment.center, Alignment.centerLeft, Alignment.centerRight etc.
ListView( children:[ Align( alignment: Alignment.center, child: SizedBox( width: 160.0, height: 160.0, child: Image.asset('images/default_avatar.jpg'), ), ), ], );
ListView( children:[ Container( alignment: Alignment.center, width: 160.0, height: 160.0, child: Image.asset('images/default_avatar.jpg'), ), ], );
Comments
Post a Comment