简体   繁体   English

如何使用 Flutter 实现像 Sliver AppBar 这样的“一个 UI”

[英]How to achieve a "One UI" like Sliver AppBar using Flutter

Inspired by Samsung's new One UI , I wanted to implement something similar using SliverAppBar in Flutter.受到三星新One UI启发,我想在 Flutter 中使用SliverAppBar实现类似的功能。 But I am unable to figure out...但我无法弄清楚......

As per One UI implementation, The SliverAppBar title should appear right in the center (both vertically and horizontally) of the expanded App Bar.根据 One UI 实现,SliverAppBar title应显示在展开的 App Bar 的中心(垂直和水平) At the same time, it should stick to the left when collapsed.同时,它在折叠时应该粘在左边。

NOTE: In my case, the App Bar contains Background Image also... So, trying to wrap the FlexibleSpaceBar with Column widget seems to make the background look weird.注意:在我的情况下,应用程序栏也包含背景图像...因此,尝试用Column小部件包装FlexibleSpaceBar似乎使背景看起来很奇怪。

I also want to get rid of extra padding on the left (which is available by default even when no "leading" widget is placed) when collapsed.我还想在折叠时摆脱左侧的额外填充(即使没有放置“前导”小部件,默认情况下也是可用的)。 Also, it would be better if the actions appear at the bottom of the SliverAppBar when expanded, so that users can reach them one-handedly...此外,如果操作在SliverAppBar时出现在SliverAppBar的底部会更好,以便用户可以单手到达它们......

One UI:一个用户界面:


扩展的 SliverAppBar 折叠的 SliverAppBar

Left ⇒ Expanded:                    Right ⇒ Collapsed:

- Actions on bottom                 - Actions as usual
- title is centered                 - title is on the left
                                      (no unwanted padding on the left of title)

I've created the One Ui Scroll View .我创建了One Ui Scroll View

You can also add actions , and customize any others.您还可以添加actions ,并自定义任何其他操作。

NestedScrollView(
    headerSliverBuilder:
        (BuildContext context, bool innerBoxIsScrolled) {
            return <Widget>[
                SliverAppBar(
                    backgroundColor: Palette.primaryBackgroundColor,
                    expandedHeight: 180.0,
                    pinned: true,
                    elevation: 0,
                    centerTitle: true,
                    flexibleSpace: FlexibleSpaceBar(
                        centerTitle: true,
                        title: Text("Attachments", style: Styles.appBarTitle),
                    ),
                ));

You can use this to get the ONE UI look that you want.您可以使用它来获得您想要的 ONE UI 外观。 The height can be changed on the expandedHeight.可以在扩展高度上更改高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 flutter 中实现此 appbar 设计,其中我将 Navigation 插入 appbar 而不是 bottomNavigationBar - How can I achieve this appbar design in flutter in which I insert Navigation inside appbar rather than bottomNavigationBar Flutter:如何在使用 Sliver 小部件时在滚动时隐藏 BottomAppBar? - Flutter: How to hide BottomAppBar on scroll when using Sliver widgets? 如何在 Flutter 中使用 GestureDetector 隐藏 appBar? - How to hide appBar using GestureDetector in Flutter? 如何在flutter中实现类似LinearLayout的布局? - how to achieve LinearLayout like layout in flutter? 如何在 Sliver 中创建自定义堆栈出现在 flutter 中? - How to create a custom stack in sliver appear in flutter? 如何使我的银色背景圈在颤动 - How to make my sliver background circle in flutter 如何像 Tinder 一样实现 Card Stack UI? - How to achieve Card Stack UI just like tinder? 如何在Android中实现像iOS一样的联系人列表UI - How to achieve contact list ui like ios in android 如何实现像这种图像布局的Android UI? 关于android:clipChildren - How to achieve Android UI like this image layout? About android:clipChildren 如何在 Flutter 中实现类似 iOS 的平滑页面过渡动画? - How to achieve iOS like smooth page transition animation in Flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM