flutter - 在 Flutter 中实现折叠工具栏

标签 flutter dart android-toolbar flutter-layout flutter-sliver

我正在尝试使用 SliverApp 栏在我的应用程序中实现折叠工具栏,但问题是当 SliverAppBar 折叠时 SliverAppBar 与我的内容重叠,我附上 gif 以供更多理解,

绿色背景中的内容位于工具栏下方,我想避免这种情况,感谢任何线索。

  @override
  Widget build(BuildContext context) {
    // TODO: implement buildr
    var _tabs = {"1", "2", "3"};
    return Scaffold(
      backgroundColor: Colors.white,
      body: NestedScrollView(
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return <Widget>[
              SliverOverlapAbsorber(
                  handle:
                      NestedScrollView.sliverOverlapAbsorberHandleFor(context),
                  child: SliverAppBar(
                    expandedHeight: 250.0,
                    floating: false,
                    pinned: true,
                    flexibleSpace: FlexibleSpaceBar(
                        centerTitle: true,
                        background: Container(
                          decoration: BoxDecoration(
                            shape: BoxShape.rectangle,
                            image: DecorationImage(
                              fit: BoxFit.fill,
                              image: CachedNetworkImageProvider(
                                  newsPost.photos[0].url),
                            ),
                          ),
                        )),
                    forceElevated: innerBoxIsScrolled,
                  ))
            ];
          },
          body: SafeArea(
            top: false,
            bottom: false,
            child: Builder(
              builder: (BuildContext context) {
                return CustomScrollView(
                  slivers: <Widget>[
                    SliverOverlapInjector(
                      handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
                          context),
                    ),
                    SliverPadding(
                      padding: const EdgeInsets.all(8.0),
                      sliver: SliverFillRemaining(child: _getBody()),
                    ),
                  ],
                );
              },
            ),
          )),
    );
  }

enter image description here

最佳答案

我认为你应该使用 SliverList而不是 SliverFillRemaining .

body: SafeArea(
        top: false,
        bottom: false,
        child: Builder(
          builder: (BuildContext context) {
            return CustomScrollView(
              shrinkWrap: true,
              slivers: <Widget>[
                SliverOverlapInjector(
                  handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
                      context),
                ),
                SliverPadding(
                  padding: const EdgeInsets.all(0.0),
                  sliver: SliverList(
                    delegate: SliverChildBuilderDelegate((context, index) {
                      return Text('Lorem ipsum dolor sit');
                    }, childCount: 1),
                  ),
                ),
              ],
            );
          },
        ),
      )

关于flutter - 在 Flutter 中实现折叠工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56820276/

相关文章:

flutter - 在 flutter 运行期间获取多个错误消息(与 gradle 相关)

reactjs - Flutter中 `componentDidMount()`的等效项是什么

android - 我想导航到屏幕并清除堆栈中的所有导航屏幕

android - 使用 appcompat-v7 在 Android 中视频播放器熄灯模式

android - 如何更改工具栏导航图标和选项菜单边距

intellij-idea - 如何在flutter中将dart SDK更新到最新的稳定版本

api - clearMarkers()和addMarker()不起作用

java - 在溢出菜单中显示图标

firebase - FutureBuilder 在显示结果之前显示错误

ios - 如何从 native ios View 弹出回 flutter View ?