dart - 使用 SizeTransition 小部件
问题描述
我想将 SizeTransition 小部件仅用于图像而不用于页面。这将是我的加载页面,在加载应用程序时,应用程序符号将显示大小转换。
https://docs.flutter.io/flutter/widgets/SizeTransition-class.html
我希望我的徽标在链接中具有这种效果。但是,我没有足够的资源来了解该小部件。你能给我一个例子吗?我试过这样的东西,但它不工作。
class _AnimTestState extends State<AnimTest>
with SingleTickerProviderStateMixin {
AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(vsync: this);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizeTransition(
child: Image.asset('assets/images/appLogo.png'),
sizeFactor: CurvedAnimation(
curve: Curves.fastOutSlowIn,
parent: controller,
),
),
);
}
}
解决方案
class _AnimTestState extends State<HomePage> with SingleTickerProviderStateMixin {
AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
duration: Duration(milliseconds: 400),
)..repeat(reverse: true); // automatically animation will be started
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizeTransition(
child: Image.asset('assets/images/appLogo.png'),
sizeFactor: CurvedAnimation(
curve: Curves.fastOutSlowIn,
parent: controller,
),
),
);
}
}
如果您不希望它像我一样自动运行,您也可以使用_controller.forward()
或按下按钮。_controller.reverse()
推荐阅读
- javascript - Vanilla 等价于 wrapInner() 用于在 li 中放置标签(无序列表)
- r - R:如何按最近的单个时间日期连接两个数据表?
- html - 表格行的高度不变
- linux - 如何查找 .desktop 文件的所有属性(名称、图标等)?
- javascript - 使用主页中的 JavaScript 在一个页面中包含多个 html 页面
- arrays - React 无法从数组中读取对象的属性
- c# - 无法将源代码文件添加到 Windows 窗体应用程序?
- amazon-web-services - 有没有办法用来自特定用户的推文触发 AWS lambda 函数
- javascript - 从数组中随机显示文本的翻转卡片
- c++ - 如何正确使用 Constructor-Function-Try-Block?