我正试图将我的应用程序更新到flutter 2.0,但我被不推荐使用的动画卡住了。我的FadeIn.dart
文件中有一些错误,该文件管理我在其他几个地方使用的类,以淡出通知和提醒用户。
这是我在文件中流行的代码
import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
class FadeIn extends StatelessWidget {
final double delay;
final Widget child;
FadeIn(this.delay, this.child);
@override
Widget build(BuildContext context) {
final tween = MultiTrackTween([
Track("opacity")
.add(Duration(milliseconds: 500), Tween(begin: 0.0, end: 1.0)),
Track("translateX").add(
Duration(milliseconds: 500), Tween(begin: 50.0, end: 0.0),
curve: Curves.easeOut)
]);
return CustomAnimation(
delay: Duration(milliseconds: (300 * delay).round()),
duration: tween.duration,
tween: tween,
child: child,
builderWithChild: (context, child, animation) =>
Opacity(
opacity: animation["opacity"],
child: Transform.translate(
offset: Offset(animation["translateX"], 0), child: child),
),
);
}
}
我在看https://pub.dev/documentation/simple_animations/latest/&https://pub.dev/packages/sa_v1_migration/versions/1.1.2但是在我改为MultiTween
之后,当我查看文档时,我对新语法感到困惑,我陷入了困境https://pub.dev/packages/sa_multi_tween它说没有什么需要改变的。这显然不是真的,我的足迹也不再被认可。
颤振错误消息。
error: The method 'MultiTrackTween' isn't defined for the type 'FadeIn'. (undefined_method at [orange_power] lib/component/FadeIn.dart:12)
error: The method 'Track' isn't defined for the type 'FadeIn'. (undefined_method at [orange_power] lib/component/FadeIn.dart:13)
error: The method 'Track' isn't defined for the type 'FadeIn'. (undefined_method at [orange_power] lib/component/FadeIn.dart:15)
warning: The parameter 'builder' is required. (missing_required_param at [orange_power] lib/component/FadeIn.dart:20)
error: The named parameter 'builderWithChild' isn't defined. (undefined_named_parameter at [orange_power] lib/component/FadeIn.dart:25)
我很难看到我需要更改什么来满足新的语法,任何帮助都将不胜感激。
import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
enum AnimationType { opacity, translateX }
class FadeAnimation extends StatelessWidget {
final double delay;
final Widget child;
const FadeAnimation(this.delay, this.child);
@override
Widget build(BuildContext context) {
final tween = MultiTween<AnimationType>()
..add(AnimationType.opacity, Tween(begin: 0.0, end: 1.0),
Duration(milliseconds: 500),)
..add(
AnimationType.translateX,
Tween(begin: 30.0, end: 1.0),
Duration(milliseconds: 500),
);
return PlayAnimation<MultiTweenValues<AnimationType>>(
delay: Duration(milliseconds: (500 * delay).round()),
duration: tween.duration,
tween: tween,
child: child,
builder: (context, child, value) => Opacity(
opacity: value.get(AnimationType.opacity),
child: Transform.translate(
offset: Offset(value.get(AnimationType.translateX), 0), child: child),
),
);
}
}
请参考:https://stackoverflow.com/a/64085688/3382061