Простые анимации Flutter: метод «[]» не может быть вызван безоговорочно, поскольку получатель может быть «нулевым».Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Простые анимации Flutter: метод «[]» не может быть вызван безоговорочно, поскольку получатель может быть «нулевым».

Сообщение Anonymous »


Поэтому я использую

Код: Выделить всё

simple_animations: ^5.0.2
package but the project that I am trying to run was made on an older version of simple animations, so I don't have much knowledge about this package but I'm trying to mimic what the old version did:

Код: Выделить всё

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

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

FadeAnimation(this.delay, this.child);

@override
Widget build(BuildContext context) {
final tween = MovieTween();

tween.tween('opacity', Tween(begin: 0.0, end: 1.0), duration: Duration(milliseconds: 500));
tween.tween('translateY', Tween(begin: -30.0, end: 0.0), duration: Duration(milliseconds: 500), curve: Curves.easeOut);

return PlayAnimationBuilder(
delay: Duration(milliseconds: (500 * delay).round()),
duration: tween.duration,
tween: tween,
child: child,
builder: (context, movie, child) => Opacity(
opacity: child['opacity'], // The method '[]' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!').
child: Transform.translate(
offset: Offset(0, child["translateY"]), child: child), // The method '[]' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!').
),
);
}
}

I get the errors on lines 23 and 25 that basically state the same thing, "The method '[]' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!')." And I don't know how to fix this please help.
Old Version

Код: Выделить всё

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

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

FadeAnimation(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("translateY").add(
Duration(milliseconds: 500), Tween(begin: -30.0, end: 0.0),
curve: Curves.easeOut)
]);

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
),
),
);
}
}


Источник: https://stackoverflow.com/questions/773 ... voked-beca
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»