animation - Flutter -Loader 动画中的缩放过渡

标签 animation dart flutter flutter-layout flutter-animation

我制作了一个带有比例转换的容器,它从 0 高度和宽度增长到 90 高度和宽度。

现在,我想做的是随着它的增长它应该慢慢淡出。我需要为不透明度创建另一个动画 Controller 吗?最好的方法是什么?有人可以帮忙吗?

我的代码看起来像这样

import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';

void main() => runApp(new MyAnimationApp());

class MyAnimationApp extends StatefulWidget {
  @override
  _MyAnimationAppState createState() => _MyAnimationAppState();
}

class _MyAnimationAppState extends State<MyAnimationApp>
    with TickerProviderStateMixin {
  Animation<double> animation;
  AnimationController _controller;

  @override
  void initState() {
    super.initState();

    _controller =
        new AnimationController(vsync: this, duration: Duration(seconds: 3))
          ..repeat();
    animation = new CurvedAnimation(parent: _controller, curve: Curves.linear);
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        body: new Container(
          child: new Center(
            child: new ScaleTransition(
              scale: animation,
              child: new Container(
                decoration: new BoxDecoration(
                    color: Color(0XFFEC3457), shape: BoxShape.circle),
                height: 90.0,
                width: 90.0,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

SS 来了

enter image description here
enter image description here

谢谢 !!!希望得到答复......

最佳答案

您需要在代码中添加一个 double 值:

double _opacity = 1;
以及在 initState 末尾的动画 Controller 的监听器
_controller.addListener(() {
  setState(() {
    _opacity = 1 - _controller.value;
  });
});
在您的小部件树上,您可以添加以下内容:
ScaleTransition(
  scale: animation,
  child: Opacity(
    opacity: _opacity,
    child: Container(
  

关于animation - Flutter -Loader 动画中的缩放过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51471376/

相关文章:

flutter - 运行时 flutter “Lost connection to device”

flutter - flutter中同步PageView和Slider的换页

flutter - Flutter Single Child Scroll View,列中的每个项目占用父级高度的1/3

c++ - WM_TIMER 动画闪烁

ios - UITableView不同cell的延时动画

dart web toolkit 自定义打开和关闭图像

ios - Flutter [firebase_messaging] IOS 构建错误

java - 如何更改javafx中按键的旋转方向

android - 如何像 "Home", "News & Weather app"那样用手指移动滑动标签内容(TabActivity)?

firebase - 如何在 Flutter 中获取嵌套 firebase 数据的所有子数据?