不同设备上键盘高度的问题 // 如何正确使用 viewInsets

发布于 2025-01-17 15:24:59 字数 634 浏览 0 评论 0原文

我有一些朋友测试了我的应用程序,并在其中一个设备上测试了键盘打开时,它隐藏了UI的一部分(复选框)。此屏幕截图显示问题(下面我的代码):

”“在此处输入图像说明”

我的相关代码从模态底部表。我不使用100%的视图插图,因为我可以覆盖的某些部分。 0.38是产生两个结果的值,构成了屏幕截图。如何在各个设备之间保持一致?

return StatefulBuilder(
    builder: (BuildContext context, StateSetter setModalState) {
  return Padding(
    padding: MediaQuery.of(context).viewInsets * 0.38,
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [//irrelevant
          ],
      

I'm having some friends test an app of mine and on one of their devices, when the keyboard is open, it hides part of the UI (a checkbox). This screenshot shows the issue (my code below):

enter image description here

Below my relevant code from the modal bottom sheet. I'm not using 100% of the view insets, as I'm fine with some part of the sheet being covered. The 0.38 is the value that produces both results form the screenshot. How can I make this consistent across devices?

return StatefulBuilder(
    builder: (BuildContext context, StateSetter setModalState) {
  return Padding(
    padding: MediaQuery.of(context).viewInsets * 0.38,
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [//irrelevant
          ],
      

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半透明的墙 2025-01-24 15:24:59

您必须使用 padding:EdgeInsets.fromLTRB(0, 0, 0, MediaQuery.viewInsetsOf(context).bottom),

在这里,LTRB 表示左、上、右、下。
当您在底部使用 MediaQuery.viewInsetsOf(context).bottom) 您的 UI 将位于键盘顶部。

You have to use padding:EdgeInsets.fromLTRB(0, 0, 0, MediaQuery.viewInsetsOf(context).bottom),

In here, LTRB means Left, Top, Right, Bottom.
When in bottom you use MediaQuery.viewInsetsOf(context).bottom) your UI will be on top of Keyboard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文