'(The getter '[' isn't defined for the type 'Object'.) - SimpleAnimation Flutter

Here's the whole code for FadeAnimation Function for every Widget

import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
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), const Duration(milliseconds: 500))
    //   ..add(AniProps.translateY, Tween(begin: -30.0, end: 0.0), const Duration(milliseconds: 500),
    //       Curves.easeOut);
    var tween = createTween();
    return PlayAnimation(
      delay: Duration(milliseconds: (500 * delay).round()),
      duration: tween.duration,
      tween: tween,
      child: child,
      builder: (context, child, animation) => Opacity(
        opacity: animation?.get(AniProps.translateY), // get animated opacity value
        child: Transform.translate(
          offset: Offset(0, animation?.get(AniProps.translateY)), // get animated offset Y value
          child: child
        ),
      ),
    );
  }
}
TimelineTween<AniProps> createTween() => TimelineTween<AniProps>()
  ..addScene(begin: Duration.zero, end: const Duration(milliseconds: 700))
      .animate(AniProps.opacity, tween: Tween<double>(begin: 0.0, end: 100.0))
      .animate(AniProps.translateY, tween: Tween<double>(begin: 300.0, end: 200.0));

The Flutter version is v2.10.5. On PlayAnimation Widget, I get the error of "The method 'get' isn't defined for the type 'Object'." because of its Object variable.

Thanks for giving additional guides



Solution 1:[1]

It looks like the type of the animation parameter passed by the builder was not inferred, so its type is object.

Try changing:

 return PlayAnimation(
   ...
 );

To:

 return PlayAnimation<TimelineValue<AniProps>>(
   ...
 );

And the animation parameter will be inferred to TimelineValue<AniProps>. Then you should be able to get the desired values.

Edit: Take a look at https://github.com/felixblaschke/simple_animations/blob/main/example/example.md#timeline-tween

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Novak