简体   繁体   English

Flutter SafeArea:避免缺口,但忽略圆角

[英]Flutter SafeArea: avoid notches, but ignore rounded corners

Is there a way to detect and avoid notches in a phone's screen (for example, the camera notch in an iPhone X), but ignore a screen's rounded corners?有没有办法检测并避免手机屏幕上的凹口(例如,iPhone X 中的相机凹口),但忽略屏幕的圆角?

For example, here's my app in landscape mode on an iPhone with a notch:例如,这是我在带缺口的 iPhone 上以横向模式运行的应用程序:

横向模式下的手机屏幕截图

The menu on the left is fine - the rounded corners of the screen don't interfere with the buttons.左边的菜单很好——屏幕的圆角不会干扰按钮。

The menu on the right is obviously problematic - the notch almost completely obscures the middle button.右边的菜单显然有问题——缺口几乎完全遮住了中间按钮。

I've played around with the SafeArea widget , but this widget avoids both notches and rounded corners, which results in a layout like this:我玩过SafeArea小部件,但这个小部件避免了缺口圆角,这导致布局如下:

与上面相同的屏幕截图,但包含在 SafeArea 小部件中

The right menu is reasonably positioned (even though it's ugly), but now the left menu bar is floating away from the edge of the screen in an attempt to avoid the rounded corners.右边的菜单位置合理(尽管它很丑),但现在左边的菜单栏从屏幕边缘浮动,试图避免圆角。

How can I get the best of both worlds?我怎样才能两全其美? I'd like the left menu bar from my first screenshot, and the right bar from the second.我想要第一个屏幕截图中的左侧菜单栏,第二个屏幕截图中的右侧栏。 Is there a way to configure the SafeArea widget to avoid notches but not rounded corners?有没有办法配置SafeArea小部件以避免缺口而不是圆角?

I just came across this in investigating https://github.com/flutter/flutter/issues/102263 .我刚刚在调查https://github.com/flutter/flutter/issues/102263时遇到了这个问题。 The margins that are being applied are correct for the device, but you may want to compose the SafeArea differently.所应用的边距对于设备是正确的,但您可能希望以不同方式组成 SafeArea。

I would explore a SafeArea inside of the widget that is inset unexpectedly.我会探索意外插入的小部件内部的 SafeArea。 If it is a widget from the Flutter framework, please file an issue on github with a reproducible code sample and we can take a look.如果它是来自 Flutter 框架的小部件,请在 github 上提交问题并提供可重现的代码示例,我们可以查看。

Wrapping it around the content within the widget is how the AppBar works to extend up into the status bar area.将它包裹在小部件内的内容周围是 AppBar 向上扩展到状态栏区域的方式。 Please see the linked issue for more context and references.请参阅链接的问题以获取更多上下文和参考。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM