How to add a ListView to a Column in Flutter?

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?

  1. 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.

  2. 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 certain height with SizedBox.

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

Leave a Comment

  Canva Pro Crack Filmora Pro Crack Spotify Premium Free Download Tradingview Premium Free