gpt4 book ai didi

flutter - 标题条不 float 在 NestedScrollView 中的列表上

转载 作者:行者123 更新时间:2023-12-03 03:32:43 25 4
gpt4 key购买 nike

我有一个 Material Design 屏幕,我在其中使用 RefreshIndicator用于拉动刷新效果。但是,我需要 RefreshIndicator出现在 SliverAppBar 下方;因此,我不能离开 SliverAppBar在列表的 CustomScrollView 内我需要在 NestedScrollView 中给它一个标题位置.
问题来了,因为我似乎无法 同步列表的一般滚动和标题 .列表滚动正常,但标题没有。我希望它在向上/向下滚动时 float 和捕捉。


class Sample extends StatefulWidget {
@override
_SampleState createState() => _SampleState();
}

class _SampleState extends State<Sample> {
final ScrollController _scrollController = new ScrollController();

@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (context, _) => [
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar(
floating: true,
snap: true,
title: Text('Title'),
),
)
],
body: Builder(
builder: (context) => RefreshIndicator(
onRefresh: () { /* do stuff */ },
child: CustomScrollView(
controller: _scrollController, // needed for an infinite scroll items loading effect
slivers: <Widget>[
SliverOverlapInjector(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context)
)
// more slivers
],
),
)
),
),
);
}
}
我想我遗漏了一些关于头条重叠的注入(inject)/吸收的东西。
如何制作 SliverAppBar和一般CustomScrollView同步滚动?

最佳答案

该解决方案适用于我的情况:
添加 floatHeaderSlivers: true到 NestedScrollView
https://github.com/flutter/flutter/issues/17518#issuecomment-641629975

关于flutter - 标题条不 float 在 NestedScrollView 中的列表上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62954907/

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