animation - 如何自动启动动画图标
问题描述
我的应用程序有一个有状态的小部件,它是配置文件区域,我想显示一个动画图标,向用户指示可以滚动屏幕,我想使用动画图标,如何在配置文件后自动为 AnimatedIcon 设置动画屏幕加载,谢谢。
Obs.: Theplay_pause
只是一个动画图标的占位符
import 'package:flutter/material.dart';
void main() {
runApp(Profile());
}
class Profile extends StatefulWidget {
@override
ProfileState createState() {
return ProfileState();
}
}
class ProfileState extends State<Profile> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: AnimatedIcon(
progress: AnimationController(
vsync: this,
duration: Duration(milliseconds: 400),
reverseDuration: Duration(milliseconds: 400),
),
icon: AnimatedIcons.play_pause,
),
)
)
);
}
}
解决方案
您必须创建一个实例AnimationController
并在initState
. animateTo
然后你可以通过调用方法来启动动画。
import 'package:flutter/material.dart';
void main() {
runApp(Profile());
}
class Profile extends StatefulWidget {
@override
ProfileState createState() {
return ProfileState();
}
}
class ProfileState extends State<Profile> with TickerProviderStateMixin {
AnimationController _animationController;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 400),
);
_animationController.animateTo(1.0);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: AnimatedIcon(
progress: _animationController,
icon: AnimatedIcons.play_pause,
),
),
),
);
}
}
推荐阅读
- node.js - 如何在特定路由器请求出现在全局错误处理程序中之前捕获它的错误
- c# - c# LiveCharts WPF如何将0值添加到数据不存在的日期以在CartesianChart中显示
- mongodb - 每个文档级别的聚合 mongodb
- excel - VBA - 如何处理名称函数的错误
- python - 如何让网络爬虫等到 javascript 函数没有执行?
- html - 使用带有 CSS 的 flex 布局时如何解决滚动条问题?
- node.js - formdata 只能正确发布文件但会删除所有字符串。(使用 node、express 和 multer)
- javascript - 结束日期大于开始日期验证
- ios - 如何在不失去对旧 iOS 版本的支持的情况下采用暗模式?
- postgresql - Postgres:事务上的ShareLock死锁