Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView inside ExpansionTile doesn't work

listview is not working inside ExpansionTile

i have tried to show a listview.builder inside ExpansionTile but it throws some exceptions

Card(
       child: ExpansionTile(
           leading: Icon(
              Icons.stars,
              color: Colors.pinkAccent,
           ),
           title: Text('Reviews',
                  style: Theme.of(context).textTheme.title,
                          ),
                children: [
                    ListView.builder(
                        itemCount: 5,
                        itemBuilder: (_, i) {
                          return (Text('item $i'));
                     })
                   ],
             ),
     ),

i want to achieve like this https://imgur.com/a/0lubABC

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 8182): The following assertion was thrown during performResize():
I/flutter ( 8182): Vertical viewport was given unbounded height.
I/flutter ( 8182): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter ( 8182): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter ( 8182): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter ( 8182): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter ( 8182): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter ( 8182): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter ( 8182): the height of the viewport to the sum of the heights of its children.
I/flutter ( 8182): 
like image 217
essayoub Avatar asked Dec 11 '22 04:12

essayoub


2 Answers

None of the above solution doesn't work as expected. So I have solved the issue. You need to use this in Listview.builder() inside ExpansionTile children:

shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),

Full Code:

                ExpansionTile( 
                    onExpansionChanged: (e){
                      //Your code
                    },
                    title: Text("You title text"),
                    children: [
                    ListView.builder(
                     shrinkWrap: true,
                     physics: NeverScrollableScrollPhysics(),
                     scrollDirection: Axis.vertical,
                     itemCount: items.length,
                     itemBuilder: (BuildContext context, int index){
                     return Text(items[index]);
                      }
                   )
                      
                    ],
                  ),
like image 187
NiiLx Avatar answered Jan 18 '23 21:01

NiiLx


The vertical size of your ListView is unbounded which makes it impossible to render. Set the shrinkWrap property of ListView to true to work around that.

like image 33
johrpan Avatar answered Jan 18 '23 22:01

johrpan