滚动时如何在Appbar上移动标题

时间:2019-08-23 08:09:26

标签: flutter

我想制作扑扑的应用程序。

滚动时如何在应用栏上制作移动标题?

我在GIF文件上附加了应用程序的状态。

我需要在哪里设置标题文本?

我只是使应用程序像Uber应用程序

snap

 @override
  Widget build(BuildContext context) {
    double sliderValue = 0.0;
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverOverlapAbsorber(
              handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
              child: SliverAppBar(
                forceElevated: innerBoxIsScrolled ,
                backgroundColor: Colors.transparent,
                leading: IconButton(
                  onPressed: () {
                    Navigator.pop(context);
                  },
                  icon: Icon(Icons.arrow_back),
                  color: Colors.black,
                ),
                elevation: 0.0,
                expandedHeight: 100.0,
                floating: false,
                pinned: true,
                flexibleSpace: FlexibleSpaceBar(
                    titlePadding: EdgeInsets.only(left: 15.0),
                    collapseMode: CollapseMode.none,
                    title: Text("Notification",
                        style: TextStyle(
                          color: Colors.black,
                          fontSize: 20.0,
                        )),
                  ),

              ),
            ),
          ];
        },
        body: Center(
          child: Text("Sample Text"),
        ),
      ),
    );
  }

1 个答案:

答案 0 :(得分:0)

必须使用CustomScrollView小部件

CustomScrollView(
      slivers: <Widget>[
        SliverAppBar(
          title: Text('Title'),
          pinned: true,
          expandedHeight: 48,
        ),
        SliverFillRemaining(
            child: Center(
          child: Text('sliver'),
        )),
      ],
    );