gpt4 book ai didi

flutter - 方法 'MultiTrackTween' 没有为类型 'FadeAnimation' 定义

转载 作者:行者123 更新时间:2023-12-05 03:40:33 25 4
gpt4 key购买 nike

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

class FadeAnimation extends StatelessWidget {
final double delay;
final Widget child;

FadeAnimation(this.delay, this.child);

///build animation track
@override
Widget build(BuildContext context) {
final tween = MultiTrackTween([
Track("opacity")
.add(Duration(milliseconds: 500), Tween(begin: 0.0, end: 1.0)),
Track("translateY").add(
Duration(milliseconds: 500), Tween(begin: -30.0, end: 0.0),
curve: Curves.easeOut)
]);

/// fade animation controller
return ControlledAnimation(
delay: Duration(milliseconds: (500 * delay).round()),
duration: tween.duration,
tween: tween,
child: child,
builderWithChild: (context, child, animation) => Opacity(
opacity: animation["opacity"],
child: Transform.translate(
offset: Offset(0, animation["translateY"]), child: child),
),
);
}
}

当我编写这段代码时,它显示方法“MultiTrackTween”没有为类型“FadeAnimation”定义。 Track 和 ControlledAnimation 也显示相同的错误。请帮忙。

最佳答案

目前方法已经改变。 MultiTrackTween 更改为 MultiTweenControlledAnimation 更改为 PlayAnimation 等等。请看下面的示例:

// Create your Animation Example
enum AniProps { opacity, translateY }

class FadeAnimation extends StatelessWidget {
final double delay;
final Widget child;

FadeAnimation(this.delay, this.child);

@override
Widget build(BuildContext context) {
final tween = MultiTween<AniProps>()
..add(AniProps.opacity, Tween(begin: 0.0, end: 1.0))
..add(AniProps.translateY, Tween(begin: -30.0, end: 0.0), Duration(milliseconds: 500), Curves.easeOut);

return PlayAnimation<MultiTweenValues<AniProps>>(
delay: Duration(milliseconds: (500 * delay).round()),
duration: tween.duration,
tween: tween,
child: child,
builder: (context, child, animation) => Opacity(
opacity: animation.get(AniProps.opacity),
child: Transform.translate(
offset: Offset(0, animation.get(AniProps.translateY)),
child: child
),
),
);
}
}

关于flutter - 方法 'MultiTrackTween' 没有为类型 'FadeAnimation' 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68067179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com