Flutter 颤振将动画从小添加到大

Flutter 颤振将动画从小添加到大,flutter,Flutter,需要知道如何在我的启动屏幕上添加一些动画。我只需要添加当应用程序打开中心图像将显示从小到大 我的代码 class _MyHomePageState extends State<MyHomePage> { @override void initState() { super.initState(); Timer( Duration(seconds: 3), () => Navigator.of(context).p

需要知道如何在我的启动屏幕上添加一些动画。我只需要添加当应用程序打开中心图像将显示从小到大

我的代码

class _MyHomePageState extends State<MyHomePage> {

  @override
  void initState() {
    super.initState();
    Timer(
        Duration(seconds: 3),
            () => Navigator.of(context).pushReplacement(MaterialPageRoute(
            builder: (BuildContext context) => HomeScreen())));
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage("assets/bg@3x.png"),
            fit: BoxFit.cover,
          ),
        ),
        child: Center(
          child: Image.asset("assets/logo@2x.png"),
        ) /* add child content here */,
      ),
    );
  }
}
class\u MyHomePageState扩展状态{
@凌驾
void initState(){
super.initState();
计时器(
持续时间(秒:3),
()=>Navigator.of(context).pushReplacement(MaterialPageRoute(
生成器:(BuildContext上下文)=>HomeScreen());
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:容器(
装饰:盒子装饰(
图像:装饰图像(
图片:AssetImage(“资产/bg@3x.png"),
适合:BoxFit.cover,
),
),
儿童:中心(
子项:Image.asset(“assets”)/logo@2x.png"),
)/*在此处添加子内容*/,
),
);
}
}

为此,您可以将
Tween
动画控制器
动画构建器
一起使用。下面是一个示例,您只需将
容器
替换为
图像
,也可以使用容器包装图像

因为,您希望
图像
在启动屏幕上增加大小,所以在
initState
中使用
AnimationController
forward()
属性

然后将图像的
height
width
属性替换为
\u animationSize.value
。根据您的需要在此处调整尺寸:

大小:

_tweenSize = Tween(begin: 50, end: 200);
_animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 400));
 AnimatedBuilder(
            animation: _animationSize,
            builder: (context, child) {
              // Put your image here and replace height, width of image with _animationSize.value
              return Container(
                color: Colors.red,
                height: _animationSize.value,
                width: _animationSize.value,
              );
            }),
持续时间:

_tweenSize = Tween(begin: 50, end: 200);
_animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 400));
 AnimatedBuilder(
            animation: _animationSize,
            builder: (context, child) {
              // Put your image here and replace height, width of image with _animationSize.value
              return Container(
                color: Colors.red,
                height: _animationSize.value,
                width: _animationSize.value,
              );
            }),
替换:

_tweenSize = Tween(begin: 50, end: 200);
_animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 400));
 AnimatedBuilder(
            animation: _animationSize,
            builder: (context, child) {
              // Put your image here and replace height, width of image with _animationSize.value
              return Container(
                color: Colors.red,
                height: _animationSize.value,
                width: _animationSize.value,
              );
            }),
类主屏幕扩展StatefulWidget{
@凌驾
_HomeScreenState createState()=>\u HomeScreenState();
}
类_homescrenstate扩展状态
使用SingleTickerProviderStateMixin{
吐温;
动画-动画化;
AnimationController _AnimationController;
@凌驾
void initState(){
_动画控制器=
AnimationController(vsync:this,duration:duration(毫秒:400));
_tweenSize=Tween(开始:50,结束:200);
_animationSize=\u tweenSize.animate(\u animationController);
_animationController.forward();
super.initState();
}
@凌驾
无效处置(){
_animationController.dispose();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:中(
子对象:动画生成器(
动画:_animationSize,
生成器:(上下文,子对象){
//将图像放在此处,并用_animationSize.value替换图像的高度和宽度
返回容器(
颜色:颜色,红色,
高度:_animationSize.value,
宽度:_animationSize.value,
);
}),
),
);
}
}