我需要在每次动画迭代之间添加一些延迟来调用重复。类似于下图。

我试图通过将值传递给 repeat 方法的 period 参数来做到这一点,但这不是我所期望的。
_controller = AnimationController(vsync: this, duration: widget.period)
..addStatusListener((AnimationStatus status) {
if (status != AnimationStatus.completed) {
return;
}
_count++;
if (widget.loop <= 0) {
//_controller.repeat(period: Duration(microseconds: 5000));
_controller.repeat();
} else if (_count < widget.loop) {
_controller.forward(from: 0.0);
}
});
Run Code Online (Sandbox Code Playgroud)
我还尝试在动画中添加 Tween。那也没有帮助。你能帮我澄清一下我哪里出错了吗?
AnimatedBuilder(
animation: Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _controller,
curve: Interval(0.5, 1.0)
),
),
child: widget.child,
builder: (BuildContext context, Widget child) => _Shiner(
child: child,
direction: widget.direction,
gradient: widget.gradient,
percent: _controller.value,
enabled: widget.enabled,
),
);
Run Code Online (Sandbox Code Playgroud) animation delay flutter flutter-animation animationcontroller
有没有办法在 Flutter 中捕获“无法加载资产:资产/图像/sample_img_url.png”错误?
我想要做的是通过提供其路径(来自 API)来加载资产图像。但是,如果我没有与给定路径关联的图像,则需要加载示例图像。
我创建了一个自定义占位符小部件,如下所示。但是它并没有像我预期的那样工作。任何人都可以帮助我吗?
class ImagePlaceHolder extends StatelessWidget {
final String path;
final double width;
const ImagePlaceHolder({Key key, this.path, this.width}) : super(key: key);
@override
Widget build(BuildContext context) {
Image finalImage;
try{
finalImage = Image.asset(
path,
width: width,
);
}
catch(Exception){
finalImage = Image.asset(
"assets/images/app_update_logo.png",
width: width,
);
}
return finalImage;
}
}
Run Code Online (Sandbox Code Playgroud)