Right now I am generating a List of ExpansionTiles using a ListView.builder. Each ExpansionTile can be expanded to view an additional list of items which is generated with a ListView.builder as well. My problem is on the second part, displaying the list once the ExpansionTile is open. When the ExpansionTile is expanded, the ExpansionTile shows the expanded shape, so it is in the expanded state, but the ListView.builder is not showing.
Structure
FutureBuilder
->returns CircularLoading Indictator if data not loaded
->Otherwise returns first ListView.builder building list with ExpansionTiles
->ExpansionTile
children: FutureBuilder **PROBLEM AREA**
-> Returns CircularLoading Indicator if data not loaded
-> Otherwise returns second ListView.builder building list with ExpansionTiles```
As denoted the issued is in the second area. Here is the code snippet
ExpansionTile(
...styling properties
onExpansionChanged: (bool expanding) => {
generateDataFunction().then((_){
setState((){
});
}
},
children: <Widget>[
FutureBuilder(
future: dataFuture,
builder: (context, snapshot) {
if(snapshot.connectionState != ConnectionState.done){
return Center(child: CircularProgressIndicator());
}
else{
return ListView.builder( // <------------- PROBLEM AREA
shrinkWrap: true, // Keep true as listview needs bounded height
itemCount: data.length
controller: dataListScrollController,
itemBuilder: (BuildContext context, int index){
return ListTile(
...I pass in my data here needed for the list tiles (title etc)
);
}
);
}
}
),
]
If I replace the ListView.builder with simply a List with a children: [] parameter and put some ListTiles in there it works fine, so I don't feel it's related to my future builder or anything. The data is there as well. I've tried forcing a size with a Container being wrapped around to make it open up larger, but no tiles are displayed.
Thanks
Edit: Adding brief ListTile
Container(
color: Colors.grey,
child: ListTile(
title: Text(widget.title w/ styling)
isThreeLine: true,
trailing: const SizedBox(),
contentPadding: EdgeInsets.only(left: 30)
subtitle: RichText(TextSpans...)
)
)
You need to pass a return function inside you itemBuilder.
Example:
You can see a ListView.builder implementation at https://api.flutter.dev/flutter/widgets/ListView-class.html