[英]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
的底部会更好,以便用户可以单手到达它们......
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.