flutter - 屏幕底部和安全区域之间的颤动位置小部件
问题描述
在我的应用程序中,我有一个bottomBar
位于右下方的SafeArea
:
问题是我想Container
在底部有一个白色(图像中的红色箭头),以便对于更大的 iPhone(屏幕底部不等于) ,safeArea
如果填充为白色,图像中的空白位置。
对于底部屏幕等于 的手机safeArea
,fillContainerHeight
应该简单地为零/零。
这是我的设置:
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
// mainAxisSize: MainAxisSize.max,
children: [
SafeArea(
child: Row(
children: [
Expanded(
child: Container(
height: 49,
color: Colors.white,
)),
Container(
height: 49,
child: Image.asset('assets/images/bottomBar.png')),
Expanded(
child: Container(
height: 49,
color: Colors.white,
)),
],
),
),
Container(color: Colors.white) // -> fill container
],
)
现在容器没有被显示。在这里解决我的问题的最佳方法是什么?我在这方面找不到任何东西。如果您需要更多信息,请告诉我!
解决方案
您可以尝试像这样使用堆栈小部件(第二个孩子(对齐小部件)位于您的 SafeArea 小部件上方):
return Stack(
children: [
SafeArea(
child: Scaffold(
appBar: AppBar(),
body: // Your other widgets here
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Colors.white,
height: MediaQuery.of(context).padding.bottom;,
),
)
],
);
另一种选择是将您的 SafeArea 包装在 Container 中并给它一个白色背景,同时将 top 属性设置为 false(= 表示 SafeArea 不会应用于顶部):
return Container(
color: Colors.white,
child: SafeArea(
top: false,
child: Scaffold(
appBar: AppBar(),
body: // Your other widgets here
),
),
);
推荐阅读
- scala - 在多个构建中加载资源时出现问题
- php - 使用包含传递变量?
- node.js - 尝试将数据从 react.js 发布到 node.js 但似乎不起作用
- mysql - 我无法创建视图
- javascript - d3.js 可见性区域计算或如何绘制地理矩形
- python - Python DateTime 索引 - 无法删除日期 - ValueError:无法将字符串转换为时间戳
- sql-server - 启用 SQL Server 身份验证 - DSN 配置
- android - 如何在 Android Studio 中导出我的项目?
- c# - 如何从 wwwroot 返回图像?
- java - Spring Azure AD - 身份验证后获取用户的地址