Flutter Gridview in Column. What's solution..?

后端 未结 5 1294
小鲜肉
小鲜肉 2021-02-02 09:16

I have a problem with gridview and column. In this case, i want put an image in upper of gridview. Please give me a solution..

return new Container(
  child: new         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-02 09:58

    Reason for the error:

    Column expands to the maximum size in main axis direction (vertical axis), and so does the GridView (scroll direction is vertical by default)

    Solution

    You need to constrain the height of the GridView, so that it expands to fill the remaining space inside Column, there are several ways of solving this issue, use whichever suits you better.


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

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

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

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

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

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

提交回复
热议问题