0

我正在尝试将我的应用程序更新到颤振 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)

我正在努力查看我需要更改哪些内容才能满足新语法,任何帮助将不胜感激。

4

1 回答 1

0
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

于 2021-12-25T08:44:03.023 回答