Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

Flutter: ListView inside Row gives me Right Overflowed

I wanted to fix my Icon Container and then make the Card Container scrollable. However, I am getting Right Overflow error. I think it is because of the Icon Container's width. How can I make my icons fixed in position and make ListView vertically scrollable at the same time?

return Row(
      children: [
        Container(
          height: 150,
          color: Colors.amber,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              IconButton(
                iconSize: 20,
                icon: Icon(Icons.add_circle_outline),
                onPressed: () {
                  print('hello');
                },
              ),
            ],
          ),
        ),
        Container(
          color: Colors.white,
          height: 150,
          child: ListView(
            shrinkWrap: true,
            scrollDirection: Axis.horizontal,
            children: [
              Card(
                child: Container(
                    color: Colors.grey,
                    width: 150,
                    child: Text('hello'),
                  ),
                ),
              ),
              Card(
                child: Container(
                    color: Colors.grey,
                    width: 150,
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );

----- Edit

So the result of the code above is like this. What I want to do is that

  • IconButton in the fix place.
  • Cards will be horizontally scrollable.

without the Right Overflow warning.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to Wrap second container with Expanded:

return Row(
      children: [
        Container(
          height: 150,
          color: Colors.amber,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              IconButton(
                iconSize: 20,
                icon: Icon(Icons.add_circle_outline),
                onPressed: () {
                  print('hello');
                },
              ),
            ],
          ),
        ),
        Expanded(child:
        Container(
          color: Colors.white,
          height: 150,
          child: ListView(
            shrinkWrap: true,
            scrollDirection: Axis.horizontal,
            children: [
              Card(
                child: Container(
                    color: Colors.grey,
                    width: 150,
                    child: Text('hello'),
                  ),
                ),
              ),
              Card(
                child: Container(
                    color: Colors.grey,
                    width: 150,
                  ),
                ),
              ),
            ],
          ),),
        ),
      ],
    );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...