I am trying to apply Fade Transition to the image on the screen, but facing error which says that state that I am using is not an argument.
I was following the official tutorial: https://www.youtube.com/watch?v=rLwWVbv3xDQ
Source:
class _MyFadeInState extends State<MyFadeIn>
with SingleTickerProviderStateMixin {
// ignore: inference_failure_on_function_return_type
MyFadeIn({@required this.child});
late AnimationController _controller;
late Animation _animation;
@override
void initState() {
_controller = AnimationController(
vsync: this,
duration: Duration(seconds: 2),
);
_animation = Tween(
begin: 0.0,
end: 1.0,
).animate(_controller);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext, context) {
_controller.forward();
createState() => _MyFadeInState();
final controller = AnimationController(
vsync: this,
duration: Duration(seconds: 2),
);
final animation = Tween(
begin: 0.0,
end: 1.0,
).animate(controller);
controller.forward();
return FadeTransition(opacity: _animation, child: widget.child);
}
}
Here's an implementation that fades in whatever child widget you pass into
MyFadeIn(see comments):Usage:
I see a bit of a misunderstanding on widgets, so I recommend studying the following: https://docs.flutter.dev/ui/widgets-intro