gpt4 book ai didi

flutter - 如何实现条状嵌套?包含条子列表的条子

转载 作者:行者123 更新时间:2023-12-03 03:22:58 30 4
gpt4 key购买 nike

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,
),
);
}
}

我没有尝试过会影响性能

关于flutter - 如何实现条状嵌套?包含条子列表的条子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61112316/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com