【问题标题】:How to move FlexibleSpaceBar to center on SliverAppbar scroll如何将 FlexibleSpaceBar 移动到 SliverAppbar 滚动的中心
【发布时间】:2020-08-12 07:13:36
【问题描述】:

我希望能够在用户向上滚动时让设置标题(位于灵活空格键中)移动到中心。我怎样才能做到这一点?

我在滚动时链接了当前屏幕的视频。正如您所看到的,当用户向上滚动时,设置标题会转到左侧而不是中心。

https://youtu.be/59MACs8jeAk

这是我的屏幕代码(并非全部只是相关的部分):

 @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: CustomScrollView(slivers: <Widget>[
          SliverAppBar(
            title: Row(
              children: <Widget>[
                Column(
                  children: <Widget>[
                    Container(
                      margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      child: IconButton(
                          onPressed: () => 
                         Navigator.pop(context),
                          //controller.toggle();
                          icon: Image.asset('assets/UI/menu.png')),
                    ),
                  ],
                )
              ],
            ),
            expandedHeight: 145.0,
            backgroundColor: Colors.white,
            //floating: true,
            pinned: true,
            elevation: 0.0,
            flexibleSpace: FlexibleSpaceBar(
              title: Row(
                children: <Widget>[

                  Container(
                      padding: EdgeInsets.fromLTRB(80, 0, 0, 0),
                      child: Text(
                        'Settings',
                        textAlign: TextAlign.left,
                        style: TextStyle(
                            color: Colors.black,
                            fontFamily: 'AvenirNext',
                            fontWeight: FontWeight.w600,
                            fontSize: 22.0),
                      )),
                ],
              ),
              background: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                      padding: EdgeInsets.fromLTRB(20, 40, 32, 0),
                      child: Text(
                        'Change Settings',
                        textAlign: TextAlign.left,
                        style: TextStyle(
                            color: Colors.black54,
                            fontFamily: 'AvenirNext',
                            fontWeight: FontWeight.w300,
                            fontSize: 16.0),
                      )),
                ],
              ),
            ),
          ),

【问题讨论】:

    标签: flutter


    【解决方案1】:

    我尝试测试您的代码,但没有成功。但是,您可以尝试更换这部分:

    title: Container(
    padding: EdgeInsets.fromLTRB(80, 0, 0, 0),
    child: Text(
      'Settings',
      textAlign: TextAlign.center,
      style: TextStyle(
          color: Colors.black,
          fontFamily: 'AvenirNext',
          fontWeight: FontWeight.w600,
          fontSize: 22.0),
    )),
    

    【讨论】:

    • 嗨 Vitor,我使用了相关的代码部分,否则它会很长,不幸的是,这不起作用,因为文本一直保持在中心,我希望它在展开时位于左侧,然后在折叠条应用栏时位于中间。谢谢
    猜你喜欢
    • 2021-05-03
    • 1970-01-01
    • 2021-11-20
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 2020-03-16
    • 2021-01-21
    • 2016-01-28
    相关资源
    最近更新 更多