animation - 为容器小部件设置动画以将屏幕留在左侧
问题描述
我想知道如何为容器小部件设置动画以将屏幕留在左侧。
我怎么做?
谢谢!
解决方案
这是您可以使用SlideTransition完成的一种方式
class SlideContainerToTheLeft extends StatefulWidget {
@override
_SlideContainerToTheLeftState createState() =>
_SlideContainerToTheLeftState();
}
class _SlideContainerToTheLeftState extends State<SlideContainerToTheLeft>
with SingleTickerProviderStateMixin {
var tween = Tween<Offset>(begin: Offset.zero, end: Offset(-2, 0))
.chain(CurveTween(curve: Curves.ease));
AnimationController animationController;
@override
void initState() {
// TODO: implement initState
super.initState();
animationController =
AnimationController(vsync: this, duration: Duration(seconds: 2));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SlideTransition(
position: animationController.drive(tween),
child: Container(
width: 300,
height: 400,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20), color: Colors.blue),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
animationController.forward();
},
),
);
}
}
希望这对您有所帮助。
推荐阅读
- pthreads - pthread_attr_t 默认属性 - 官方文档
- ios - 无法使用 Transporter 将应用程序上传到 iTunesConnect
- amazon-web-services - 如何在使用打包程序构建 AWS AMI 时解决 spin-clouddriver-57bdcf65fd-dm5mq 和 spin-clouddriver-57bdcf65fd-fpqh9 错误
- command - Windows 终端:打开多个窗格并执行指定命令
- spring - spring data mongo多数据库事务如何实现
- python - 具有现有 while 循环的 Pi GUI
- php - 准备请求
- r - 将多个图分成 4 个不同的图
- javascript - 在frida中生成特定值时如何hook
- flutter - chart_flutter 上刻度项的事件侦听器