flutter - 如何保持小部件的位置
问题描述
我正在尝试为字母添加动画,如下所示。我面临的问题是,当我更改所选字母的大小时,其他元素正在移动。我找不到保持其他字母位置的方法。有任何想法吗?
return Container(
color: Colors.orange,
padding: EdgeInsets.fromLTRB(5, 0, 5, 0),
child: RowSuper(
alignment: Alignment.center,
innerDistance: -20,
children: [
nodes[0],
ColumnSuper(
alignment: Alignment.center,
innerDistance: -5,
children: [
nodes[1],
nodes[2],
],
),
nodes[3],
]));
return TweenAnimationBuilder(
tween: Tween<double>(begin: 0, end: 1),
duration: Duration(milliseconds: 2000),
builder: (BuildContext context, double _val, Widget child) {
return Opacity(
opacity: _val,
child: HiveNode(
index: index,
child: Container(
height: _val * size,
width: _val * size,
decoration: ShapeDecoration(
color: nodeColor,
shape: PolygonBorder(
sides: 6,
rotate: 90.0,
borderRadius: 8.0,
border: BorderSide(color: Colors.grey, width: 0.1)),
shadows: [
BoxShadow(
color: Colors.grey.withOpacity(0.6),
spreadRadius: 0,
blurRadius: 7,
offset: Offset(-3, 6), // changes position of shadow
),
],
),
child: Center(
child: Text(char,
style: TextStyle(
fontSize: 34,
fontWeight: FontWeight.bold,
color: textColor)),
))),
);
});
解决方案
我可以用 Stack 方法解决。如果将来有人需要类似的东西,这就是答案。
return Container(
color: Colors.orange,
width: 360,
height: 400,
child: Stack(
alignment: Alignment.center,
children: [
Positioned(left:0, top:80, child: nodes[0]),
Positioned(left:0, bottom:80, child: nodes[1]),
Positioned(top:20, child: nodes[2]),
Positioned(left:120, top:140, child: nodes[3]),
Positioned(bottom:20, child: nodes[4]),
Positioned(right:0, top:80, child: nodes[5]),
Positioned(right:0, bottom:80, child: nodes[6]),
],
)
);
推荐阅读
- powershell - Powershell:JSON的对象列表
- swift - 在 iOS14.4 的 SwiftUI 中使用 .insetGrouped listStyle for List 导致数据问题
- jenkins-pipeline - 如何修复“groovy.lang.MissingMethodException:没有方法签名:Script1.pipeline() 适用”
- visual-studio-code - 在 VSCode 中获取大文件的整理搜索结果
- c++ - 这个警告在 C++ 中对异常处理意味着什么?
- linux - 什么意思。在命令行的开头
- python-3.x - 如何在课程中存储和跟踪分数?
- linux - 如何在我的 VM 之外访问 webpack dev-server?
- java - 是否可以在工厂表达式中插入案例生成器?
- python - 我正在尝试使用 request 和 bs4 python 模块从网站中提取数据。当我尝试访问此代码时,收到以下 json 错误消息