flutter - 确保 transform.translate 不会离开容器
问题描述
有没有办法确保 Transform.translate 不会超出容器?即使这些价值观在逻辑上把它放在外面?因此,如果容器位于屏幕的中心并且在该容器的 -200 处移动了某些东西,我希望它只显示容器内部的部分 SizedBox 和 ConstrainedBox 似乎没有帮助
我当前的代码是:
return ConstrainedBox(
constraints: BoxConstraints.tight(Size(400, 400)),
child: Container(
width: 400,
height: 400,
color: Colors.blue,
child: Stack(
children: [
AnimatedBuilder(
animation: animationController,
child: // ...,
builder: (BuildContext context, Widget child) {
return Transform.translate(
offset: Offset(positionLeft, positionRight),
child: child
);
},
),
//...
]
)
)
)
解决方案
显然我找到了一个解决方案,用 ClipRect 而不是 ContrainedBox 包装容器做到了
推荐阅读
- axios - 在 Nuxt 中刷新页面后,Axios 我的令牌消失了
- reactjs - indexOf() 没有按预期工作,函数不断添加重复项 - React
- python - 通过 GUI 使用 python 自动化导航
- go - 如何在 Go 中打印 http 响应正文?
- typescript - 在最终响应之前获取内容处置标头的最佳实践
- python - Python:函数返回的值未在熊猫数据框中更新
- mongoose - 为什么 next-auth 给出 TypeError 无法解构“连接”的属性“管理器”,因为它为空?
- python-3.x - 调试由服务器重新启动修复的 Twilio SSL 错误(错误 11220)
- python-3.x - 如何用 pyshark 嗅探 l2cap 数据包?
- .net - .NET v3.5 程序集可以引用 .NET v4.5 程序集吗?