对于更新版本GridView
,使用SliverToBoxAdapter
并将 gridView 设置physics
为NeverScrollableScrollPhysics
因为CustomScrollView
将处理滚动事件。
SliverToBoxAdapter(
child: GridView.custom(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
测试小部件
Scaffold(
body: CustomScrollView(
slivers: [
const SliverAppBar(
title: Text("title"),
),
SliverToBoxAdapter(
child: GridView.custom(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: SliverQuiltedGridDelegate(
crossAxisCount: 4,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
repeatPattern: QuiltedGridRepeatPattern.inverted,
pattern: const [
QuiltedGridTile(2, 2),
QuiltedGridTile(1, 1),
QuiltedGridTile(1, 1),
QuiltedGridTile(1, 2),
],
),
childrenDelegate: SliverChildBuilderDelegate(
(context, index) => Container(
color: Colors.cyanAccent,
child: Text("$index"),
),
childCount: 44,
),
),
)
],
)),
flutter_staggered_grid_view: ^0.4.1
提供SliverStaggeredGrid
用作sliver
的孩子。
CustomScrollView(
slivers: [
SliverStaggeredGrid.countBuilder(...