我终于找到了一个解决方案,它包括使用Positioned()Widget到absolute position Widget。使改变translate向呈现流中的小部件当前位置添加一个翻译,这就是为什么移除一个小部件会使其余的小部件移动。
代码变成:
// == Build the scene
return Stack(clipBehavior: Clip.none, children: [
// == The whole scene debug materialisation
if (debug)
Positioned(left: 0, top: 0, child: SizedBox(
width: size.width,
height: size.height,
child: Container(
color: const Color(0x7ff67e22),
))),
// == Add ground
Positioned(left: 0, top: 0, child: hill),
// == The pump
Positioned(left: punmpOffsetX, top: 120, child:
offset: Offset(punmpOffsetX /*- 115 / 2*/, 120),
child: Container(
width: 150,
child: ScaleTransition(
scale: Tween<double>(begin: 3, end: 1).animate(
CurvedAnimation(
parent: _controller, curve: Curves.elasticOut)),
child: Pump(offset: Offset.zero, width: 150)))),
// == The animated vehicle
Positioned(left: 0, top: 0, child: DrivingVehicle(hill: hill)),