lutter的滚动视图中将容器或其他任何小部件固定在appbar

lutter的滚动视图中将容器或其他任何小部件固定在appbar

本文介绍了如何在flutter的滚动视图中将容器或其他任何小部件固定在appbar下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在滚动屏幕时将小部件放置在应用程序下方.该屏幕包含一个浮动的应用栏,该栏具有灵活的空间(sliverappbar),在其下方是一个容器,可显示任何容器或选项卡视图.链接中的视频是我想要的效果的示例.

I want a widget to be place below the app while scrolling the screen .The screen contains a floating app bar with flexible space ( sliverappbar) and below it one conatiner which have any container or tab view .The video in the link is the example of the effect i wanted.

推荐答案

好的,我想我现在已经了解您了.您需要实现一个CustomScrollView

Alright, I think I understand you now. You'll need to implement a CustomScrollView

CustomScrollView(
              slivers: <Widget>[
                SliverAppBar(
                    // Your appbar goes here
                    ),
                SliverPersistentHeader(
                  pinned: true,
                  delegate: PersistentHeader(
                    widget: Row(
                      // Format this to meet your need
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text('Hello World'),
                        Text('Hello World'),
                        Text('Hello World'),
                      ],
                    ),
                  ),
                ),
              ],
            ),

为Persistent标头创建一个新类,该类扩展了SliverPersistentHeaderDelegate,如下所示:

Create a new class for the Persistent header, which extends a SliverPersistentHeaderDelegate as shown:

class PersistentHeader extends SliverPersistentHeaderDelegate {
  final Widget widget;

  PersistentHeader({this.widget});

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Container(
      width: double.infinity,
      height: 56.0,
      child: Card(
        margin: EdgeInsets.all(0),
        color: Colors.white,
        elevation: 5.0,
        child: Center(child: widget),
      ),
    );
  }

  @override
  double get maxExtent => 56.0;

  @override
  double get minExtent => 56.0;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
    return true;
  }
}

如果您遇到其他任何问题,请告诉我.

Let me know if you encounter any other issue.

这篇关于如何在flutter的滚动视图中将容器或其他任何小部件固定在appbar下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:55