Custom Flutter widget to return two widgets for use with CustomScrollView / slivers
302
You can bundle MyCustomTitle
and MyCustomSliverGrid
into one widget with MultiSliver.
class MyCustomSliverGridWithTitle extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiSliver(
children: <Widget>[
MyCustomTitle(...),
MyCustomSliverGrid(...),
],
);
}
}
Author by
TechAurelian
Updated on December 03, 2022Comments
-
TechAurelian over 1 year
I have a Flutter CustomScrollView with the following structure:
body: CustomScrollView( slivers: <Widget>[ MyCustomTitle(...), MyCustomSliverGrid(...) MyCustomTitle(...), MyCustomSliverGrid(...) MyCustomTitle(...), MyCustomSliverGrid(...) ... ], ),
MyCustomTitle
extendsStatelessWidget
and in thebuild
method returns aSliverToBoxAdapter
widget, and theMyCustomSliverGrid
widget extendsStatelessWidget
and in thebuild
method returns aSliverGrid
widget.How can I implement a single Widget (
MyCustomSliverGridWithTitle
) that returns both the custom title and the custom SliverGrid? From thebuild
method of aStatelessWidget
I can only return a single Widget, not two.-
Till Friebe about 3 yearsI have the same problem and could not solve it, so I created an issue.
-