'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) {...},
),
),
],
),
),
);
Solution 1:[1]
can you try to remove Expanded Widget on just above the List view Builder
Solution 2:[2]
Add the listview inside a sizedbox widget and set height to the sizedbox widget
Solution 3:[3]
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) {...},
),
],
),
),
);
Solution 4:[4]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Akbar Masterpadi |
| Solution 2 | Anas Nadeem |
| Solution 3 | lejlun |
| Solution 4 | Muhammad El-Sayed |
