Flutter ListView.Builder() in scrollable Column with other widgets

前端 未结 12 588
情书的邮戳
情书的邮戳 2020-12-24 10:58

I have a TabBarView() with an amount of different views. I want of them to be a Column with a TextField at top and a ListView.Builder() below, but both widgets should be in

12条回答
  •  無奈伤痛
    2020-12-24 11:49

    Reason for the error:

    Column expands to the maximum size in main axis direction (vertical axis), and so does the ListView

    Solution

    You need to constrain the height of the ListView, so that it does expand to match Column, there are several ways of solving this issue, I'm listing a few here:


    1. If you want to allow ListView to take up all remaining space inside Column use Flexible.

      Column(
        children: [
          Flexible(
            child: ListView(...),
          )
        ],
      )
      

    1. If you want to limit your ListView to certain height, you can use SizedBox.

      Column(
        children: [
          SizedBox(
            height: 200, // constrain height
            child: ListView(),
          )
        ],
      )
      

    1. If your ListView is small, you may try shrinkWrap property on it.

      Column(
        children: [
          ListView(
            shrinkWrap: true, // use it
          )
        ],
      )
      

提交回复
热议问题