Hello Guys How are you all? Hope You all are fine. Today In this article we are going to learn How to add a ListView to a Column in Flutter? So Without Wasting your time, Lets start this article without Wasting your time. Here we will discuss all possible way to add listview to a column.
How to add a ListView to a Column in Flutter?
- How to add a ListView to a Column in Flutter?
To add a ListView to a Column in Flutter plest and easiest solution is Just use
Expanded
widget to expand remain space Second solution is As You know this error is occurs caue of ListView essentially has an infinite height So That you just have to add a height constraint to your list using container with height. - Add a ListView to a Column in Flutter
To add a ListView to a Column in Flutter Here ListView essentially has an infinite height it will cause an error So that Just limit your
ListView
to certainheight
withSizedBox
.
Method 1: use Expanded
Simplest and easiest solution is Just use Expanded
widget to expand remain space. Here Is Example Code.
Column(
children: <Widget>[
Expanded(
child: yourList,
)
],
);
Method 2: use SizedBox
Here ListView essentially has an infinite height it will cause an error So that Just limit your ListView
to certain height
with SizedBox
. Here is My Example Code.
Column(
children: <Widget>[
SizedBox(
height: 200, // certain height
child: ListView(),
)
],
)
Method 3: specify size
As You know this error is occurs caue of ListView essentially has an infinite height So That you just have to add a height constraint to your list using container with height. Just like below example.
Container(
height: 44.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
RaisedButton(
onPressed: null,
child: Text("snippet1"),
),
Padding(padding: EdgeInsets.all(5.00)),
RaisedButton(
onPressed: null,
child: Text("snippet2"),
)
],
),
)
Method 4: Use Flexible
Here we will use Flexible
widget as it will only take the space it required. For Example.
Column(
children: <Widget>[
Flexible(
child: ListView(...),
)
],
)
Summary
It’s all About this article. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read
- Error: The non-abstract class ‘InternalSelectableMathState’ is missing implementations for these members
- xcodebuild: error: Could not resolve package dependencies: Internal error: missingPackageDescriptionModule
- FirebaseOptions cannot be null when creating the default app
- Could not GET ‘https://google.bintray.com/exoplayer/com/google/android/gms/play-services-location/maven-metadata.xml’. Received status code 502 from server: Bad Gateway
- Execution failed for task ‘:camera:compileDebugJavaWithJavac’ in Flutter