flutter - 如何在 flutter 中的每次重复动画之间添加延迟

标签 flutter dart animation

我的应用程序中有一个带有容器的 SlideTransition,它会永远重复,但我希望在每次重复后都有延迟。所以它会是这样的:Visual Representation

这是我的代码

  late final AnimationController _animationController = AnimationController(
    vsync: this,
    duration: const Duration(seconds: 1)
  )..repeat(reverse: true); // Here there should be the 500 millisecond delay

  late final Animation<Offset> _animation = Tween<Offset>(
    begin: Offset.zero,
    end: Offset(0, 1),
  ).animate(_animationController);

. . .

return Scaffold(
  body: Center(
    child: SlideTransition(
      position: _animation,
      child: Container(
        height: 100,
        width: 100,
        color: Colors.red,
      ),
    ),
  ),
);


   

最佳答案

只需更改您想要的持续时间 => await Future.delayed(Duration(seconds: 3)); 我用 seconds: 3 测试它以获得更好的想法。

 late final AnimationController _animationController =
      AnimationController(vsync: this, duration: const Duration(seconds: 3))
        ..forward(); 
 @override
  void initState() {
    super.initState();

    _animationController.addListener(() async {
      print(_animationController.status);

      if (_animationController.isCompleted) {
        await Future.delayed(Duration(seconds: 3));
        _animationController.reverse();
      } else if (_animationController.isDismissed) {
        await Future.delayed(Duration(seconds: 3));
        _animationController.forward();
      }
    });
  }

关于flutter - 如何在 flutter 中的每次重复动画之间添加延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68807827/

相关文章:

jQuery 动画输入值

debugging - 如何从flutter应用程序发送打印日志?

dart - Flutter 在 `flutter` 命令上失败

flutter - 搜索委托(delegate),当我单击“搜索”按钮时,它会显示带有错误子项的红色屏幕! =空

flutter - 如何对齐 TextFields 例如列中的文本()?

flutter - Dart:无法访问嵌套的 map 对象

animation - Sprite 是如何工作的?

css preserve 3d with rotate animation 在最新的浏览器上不再工作

android - Flutter 图像选择器崩溃

flutter - Flutter:检查AppLifecycle事件挂起