Flutter NestedScrollView 没有立即显示浮动的 SliverAppBar?

Kar*_*rin 5 flutter flutter-sliver

我尝试使用 NestedScrollView 创建带有浮动 SliverAppBar 的滚动视图,并在 CustomScrollView 中添加内容,我需要将其分开,因为我还使用了 pull_to_refresh 插件来处理 api 请求。

但是,如果我向上滚动以显示浮动 SliverAppBar,它不会像我预期的那样工作,它仅在用户停止滚动后显示

有没有办法用 NestedScrollView 来实现这一点?或者也许是其他小部件,我需要将其与 CustomScrollView 分开,因为如果我在 CustomScrollView 中使用浮动 SliverAppBar,我的加载指示器将与浮动 SliverAppBar 重叠

这是我尝试过的代码

Scaffold(
        body: SafeArea(
          child: Scrollbar(
            child: NestedScrollView(
                    headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
                        // These are the slivers that show up in the "outer" scroll view.
                        return <Widget>[
                            SliverAppBar(
                                title: const Text('Books Nested'), // This is the title in the app b
                                forceElevated: innerBoxIsScrolled,
                                floating: true,
                                snap: true,
                            ),
                        ];
                    },
                    body: CustomScrollView(
                        slivers: <Widget>[
                            SliverList(
                                delegate: SliverChildBuilderDelegate(
                                        (BuildContext context, int index) {
                                        return Container(
                                            margin: EdgeInsets.all(10.0),
                                            color: Colors.grey,
                                            constraints: BoxConstraints(
                                                minWidth: 100.0,
                                                maxHeight: 160.0
                                            ),
                                        );
                                    },
                                    childCount: 30
                                ),
                            ),
                        ],
                    )
                ),
          )
        ),
    );
Run Code Online (Sandbox Code Playgroud)

结果:NestedScrollView 内的 SliverAppBar NestedScrollView 内的 SliverAppBar

我想要得到这样的东西,这是我只用 CustomScrollView 制作的来存储 SliverAppBar 和 SliverList 的东西。

CustomScrollView 内的 SliverAppBar CustomScrollView 内的 SliverAppBar