rozerro
rozerro

Reputation: 7216

Trying to put a ListView.builder inside a Column with other childrens

I get this error when try to make this composition of Column and ListView.builder

======== Exception caught by rendering library ===================================================== RenderBox was not laid out: _RenderSingleChildViewport#1fb04 relayoutBoundary=up10 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 1930 pos 12: 'hasSize'

How to fix it?

return Scaffold(
  appBar: AppBar(),
  body: SingleChildScrollView( // The relevant error-causing widget
    child: Column(
      children: [
        for (int i = 0; i < 100; i++)
          Padding(
            padding: const EdgeInsets.all(20.0),
            child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [...],
              ),
          ),
          Expanded(
            child: ListView.builder(
              itemCount: 100,
              itemBuilder: (BuildContext context, int index) {...},
          ),
        ),
      ],
    ),
  ),
);

Upvotes: 0

Views: 3704

Answers (4)

Muhammad El-Sayed
Muhammad El-Sayed

Reputation: 1

problem : List view inflate as can take all space and u put it in Expanded widget inside column so you give infinity space to it . salutation : just wrap this Expanded widget to container , Give fixed height and width for this container and it will work.

Upvotes: 0

Prateek Jain
Prateek Jain

Reputation: 614

remove the Expanded widget and assign shrinkWrap property of Listview.builder to true

return Scaffold(
  appBar: AppBar(),
  body: SingleChildScrollView( // The relevant error-causing widget
    child: Column(
      children: [
        for (int i = 0; i < 100; i++)
          Padding(
            padding: const EdgeInsets.all(20.0),
            child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [...],
              ),
          ),
          ListView.builder(
              shrinkWrap: true,
              itemCount: 100,
              itemBuilder: (BuildContext context, int index) {...},
          ),
      ],
    ),
  ),
);

Upvotes: 3

Anas Nadeem
Anas Nadeem

Reputation: 897

Add the listview inside a sizedbox widget and set height to the sizedbox widget

Upvotes: 0

Akbar Masterpadi
Akbar Masterpadi

Reputation: 1196

can you try to remove Expanded Widget on just above the List view Builder

Upvotes: 0

Related Questions