【问题标题】:How to move the actions along with title in flexibleSpace in SliverAppBar in Flutter?如何在 Flutter 的 SliverAppBar 中的flexibleSpace 中移动动作和标题?
【发布时间】:2019-08-22 07:18:43
【问题描述】:

我正在尝试在 Flutter 中实现类似的东西。

https://a.imge.to/2019/08/22/mgrjU.png

但我现在被困在这个问题上。

https://a.imge.to/2019/08/22/mgB62.png

操作按钮固定在 UI 的顶部,不随文本移动。有什么办法可以把他们打倒在裂片妖中?

我还没有找到一种方法来向 SliverAppBar 的 flexibleSpace 部分添加操作


SliverAppBar(
      floating: false,
      pinned: true,
      expandedHeight: 150.0,
      backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
      flexibleSpace: const FlexibleSpaceBar(
        title: Text("User Status", textAlign: TextAlign.justify,),
        titlePadding: EdgeInsets.all(15.0),
      ),
      actions: [
        IconButton(
          icon: Icon(Icons.refresh),
          onPressed: () {},
        ),
        IconButton(
          icon: Icon(Icons.search),
          onPressed: () {},
        )
      ],
    );

我希望操作按钮与标题文本一起出现。当用户滚动时,按钮应该随着标题文本移动。

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:

    我不确定你是怎么做到的,试试这个工作代码。

    输出:

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
        body: CustomScrollView(
          slivers: <Widget>[
            SliverAppBar(
              floating: false,
              pinned: true,
              expandedHeight: 150.0,
              backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
              flexibleSpace: Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: <Widget>[
                  Container(
                    width: 200,
                    child: FlexibleSpaceBar(title: Text("User Status")),
                  ),
                  Spacer(),
                  IconButton(
                    icon: Icon(Icons.refresh),
                    onPressed: () {},
                  ),
                  IconButton(
                    icon: Icon(Icons.search),
                    onPressed: () {},
                  )
                ],
              ),
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate((_, i) {
                return ListTile(title: Text("Item ${i}"));
              }, childCount: 20),
            ),
          ],
        ),
      );
    }
    

    【讨论】:

    • 在这个例子中,只有文本“用户状态”在滚动列表时移动。并且这些行动一直被固定在顶部。我希望将动作与文本一起移动。
    猜你喜欢
    • 1970-01-01
    • 2019-05-26
    • 2021-11-20
    • 2020-02-17
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 2020-08-12
    • 2021-03-13
    相关资源
    最近更新 更多