22

I'm attempting to create a scrollable listview inside of a container which also contains a static image. However, the listview doesn't appear to be scrollable and I get a "bottom overflow by x pixels" artifact on my app.

enter image description here

  static List<Widget> getClubs() {
    var myClubs = new List<Widget>();
    for (var i = 0; i < 10; i++) {
      myClubs.add(new Padding(
          padding: EdgeInsets.all(8.0),
          child: new CircleAvatar(
            backgroundImage:
                new NetworkImage("https://i.imgur.com/p2oUDLD.png"),
            backgroundColor: Colors.black,
            radius: 34.0,
          )));
    }
    return myClubs;
  }

  final leftSection = new Container(
      color: Color(0xFF212121),
      width: 100,
      child: Column(
        children: <Widget>[
          SizedBox(height: 20.0),
          new Image.asset(
            'assets/logo.png',
            alignment: Alignment.center,
          ),
          SizedBox(height: 10.0),
          new Container(
              child: new ListView(
            shrinkWrap: true,
            padding: const EdgeInsets.all(5.0),
            children: getClubs(),
          ))
        ],
      ));

6 Answers 6

43

You can use Expanded widget or set the height for the Container.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes! Something yet so simple has taken so long to figure out. Thanks.
@Zander17 +1 that
3
Flexible(child: ListView.builder(..))

1 Comment

Your answer could be improved by adding more information on what the code does and how it helps the OP.
2

I would also recommend Wrap for anyone running into an issue where a container is sized wrong within the listview, causing an overflow:

                          new Container(
                             alignment: Alignment.center,
                             child: Wrap( //the magic
                               children: [
                                 new Container(),
                               ],
                             ),
                           ),

Comments

2

wrap the Column in an Expanded widget:

Expanded(
  child: Column(
  ),
),

Another way is to wrap the Column in a Flexible widget and specify a flex factor.

Flexible(
           flex: 1,
           child: Column(
            children: [
                      
                  ],
               ),
           ),

Comments

1

Sometimes best way to fix an estimated height is using sizedbox

      int heightToBeReduced = 380;

      SizedBox(
        height: MediaQuery.of(context).size.height - heightToBeReduced,
        child: ListView....
      )

Comments

0

I used a Flexible in a Row to control the output of the listview builder

Define the scollController

    final _scrollController = ScrollController();

Define the ListView builder

    ListView builder = ListView.builder(
    itemCount: listPerformance?.length,
    shrinkWrap: true,
    itemBuilder: (context, index) {
      return PerformanceCardWidget(performanceView: listPerformance[index]);
    });

Define a flexible that outputs the listview builder contents

    Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
    Flexible(
          flex: 6,
          fit: FlexFit.loose,
          child: Scrollbar(
              isAlwaysShown: true,
              controller: _scrollController,
              child: SingleChildScrollView(
                  controller: _scrollController, child: builder))
          )
     ])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.