SliverList
是一个包含盒子小部件的小条。是否有包含条子小部件的条子?
我正在尝试嵌套flutter_sticky_headers来创建时间轴,但是SliverStickyHeader
仅接受单个条作为参数(请参阅monthSlivers()
中的注释)。
class HomeView extends StatelessWidget {
final HomeViewModel viewModel;
HomeView(this.viewModel);
List<Widget> entryTiles(List<EntryTileViewModel> entryVMs) {
return entryVMs.map((entryVM) => EntryTile(viewModel: entryVM)).toList();
}
List<Widget> daySlivers(List<DaySection> daySections) {
return daySections.map((daySection) {
var entries = entryTiles(daySection.entryVMs);
return SliverStickyHeader(
overlapsContent: true,
header: DayHeader(
viewModel: DayHeaderViewModel(date: daySection.date),
),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => entries[i],
childCount: entries.length,
),
),
);
}).toList();
}
List<Widget> monthSlivers() {
return viewModel.monthSections.map((monthSection) {
var days = daySlivers(monthSection.daySections);
return SliverStickyHeader(
header: MonthHeader(
viewModel: MonthHeaderViewModel(date: monthSection.date),
),
sliver:,// THIS IS WHERE I WANT TO PUT DAYSLIVERS().
);
}).toList();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: CustomScrollView(
slivers: monthSlivers(),
),
);
}
}
最佳答案
我现在在我的项目中使用这个
class SliverSection extends StatelessWidget {
final List<Widget> slivers;
const SliverSection({Key key, this.slivers}) : super(key: key);
@override
Widget build(BuildContext context) {
return SliverToBoxAdapter(
child: ShrinkWrappingViewport(
offset: ViewportOffset.zero(),
slivers: slivers,
),
);
}
}
我没有尝试过会影响性能