flutter - 在堆栈中按基线对齐图标
问题描述
我需要将一个图标的基线居中,在堆栈的中心:
我试试这个
class Screen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Tst")),
body: Stack(
children: <Widget>[
Container(
color: Colors.white,
),
Positioned(
bottom: context.size.height / 2,
width: context.size.width,
child: Align(
alignment: Alignment.bottomCenter,
child: Icon(
Icons.add_location,
size: 100,
),
)),
],
));
}
}
但是收到错误:
“在构建过程中无法获取大小。” “这个渲染对象的大小还没有确定,因为框架还在”
解决方案
"Cannot get size during build." "The size of this render object has not yet been determined because the framework is still in the process of building widget"
The error is very obvious. You can not calculate the size of the widget before it is built.
A better alternative is to use Center
widget in this case as suggested by hayi:
Center(
child: Align(
alignment: Alignment.bottomCenter,
child: Icon(
Icons.add_location,
size: 100,
),
)),
The above code is just an example.
Hope this helps
推荐阅读
- opencv - 如何从 Python OpenCV 从模拟摄像机(HIWATCH DS-T101)获取视频
- python - 如何在熊猫中使用 groupby 查找百分比 - 不是总数,而是单个邻域过滤器
- azure - 无法为容器创建 Web 应用程序 - resourceId 长度太短:
- java - 无法连接数据库?
- c# - 反序列化 json newtonsoft 将对象的所有内容都保留在 null C#
- synchronization - 让 Unison 记住已同步的文件,尽管它们已从一个副本中删除?
- git - 如何在 Azure DevOps 中创建使用外部 git 存储库和个人身份验证令牌的管道
- numpy - 为什么 Julia 中的三角函数似乎比 Numpy 慢?
- python - 如何访问批量编辑按钮“bulkedit_all”?蟒蛇/硒
- java - 替代已弃用的方法 sparksession.read.json(JavaRDD)