'SliverList inside ExpansionTile without Shrinkwrap (Flutter)
Is there any way to build a SliverList inside ExpansionTile? The reason I want to do this, I have a really large amount of data that needs to be put inside the expansion tile. Expansion tile needs List but SliverList should be inside CustomScrollView. If I use custom Scroll View inside Expansion tile's Children and put SliverList in it renders nothing. If I set Shrinkwrap true to CustomScrollView it renders Every Widget at a time. So, How can it be fixed?
Here is an example,
class Expamle extends StatelessWidget {
const Expamle({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return CustomScrollView(
slivers: [
....,
SliverList(
delegate: SliverChildBuilderDelegate(
(_, i) => ExpansionTile(
title: const Text('Title'),
children: [
// But it is Illegal here
SliverList(
delegate: SliverChildBuilderDelegate(
(_, i) => const Text('Child'),
childCount: 10,
),
),
// It does not render anything
CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(_, i) => const Text('Child'),
childCount: 10,
),
),
],
),
// It Works but render all widgets at a time
CustomScrollView(
shrinkWrap: true,
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(_, i) => const Text('Child'),
childCount: 10,
),
),
],
),
],
),
),
),
],
);
}
}
Solution 1:[1]
Definitely not a proper solution but just a rought workaround. I need the same functionality and it seems it can't be achieved with Flutter currently. So I ended up changing the design a bit. Instead of having a full list of data in your expansion tile, you can just show a preview of some small number of items which can be rendered at once safely. Then, at the end of this short list, add a "Show all (number)" button which will show the full data in a separate screen or dialog.
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 | ?????? ??????? |