I had a CustomScrollView
which looked like:
CustomScrollView(
slivers: [
SliverPersistentHeader(
floating: true,
delegate: MyPersistentHeaderDelegate(),
),
SliverList(...),
],
)
Because I had to change the layout to use masonry layout I am using flutter_staggered_grid_view
packages MasonryGridView
. The problem is it does not support slivers and therefor i cannot use it in CustomScrollView.
The question is how can I now still use my SliverPersistentHeader (/Delegate) without using a CustomScrollView?
Ive tried using a NestedScrollView
but all the examples only show how it works with CustomScrollView:
NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (BuildContext _, bool innerBoxIsScrolled) {
return <Widget>[
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverPersistentHeader(
delegate: MyPersistentHeaderDelegate(),
floating: true,
),
),
];
},
body: CustomScrollView(
sliver: [
SliverOverlapInjector(handle: handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context)),
// wont work in sliver because it uses its own scroll view
MasonryGridView.builder(),
]
)
),
Actually you can use the
SliverMasonryGrid
widget inside aCustomScrollView
, as explained in flutter_staggered_grid_view's wiki.Here's a code sample inspired by the documentation that has been working well for me:
Code sample