Flutter The getter 'value' was called on null. / Receiver: null / Tried calling: value

Viewed 381

I'm animating a image on 360 degree, I write code and initialize some properties Here's the code :

import 'package:flutter/material.dart';
import 'dart:math' as math;

class BasicAnimations extends StatefulWidget {
  @override
  _BasicAnimationsState createState() => _BasicAnimationsState();
}

class _BasicAnimationsState extends State<BasicAnimations>
    with SingleTickerProviderStateMixin {

  Animation<double> _animation;
  AnimationController _animationController;

  @override
  void initState() {
    _animationController = AnimationController(duration: Duration(milliseconds: 1500) ,vsync: this);

    _animation = Tween<double>(begin: 0, end: 2 * math.pi).animate(_animationController);
    _animationController.forward();

    super.initState();
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text("Basic Animations"),
      ),

So there in body: Transform.rotate I set the _animation.value and this thorw error 'value' was called on null code :

body: Transform.rotate(
        angle: _animation.value,
        child: Center(
          child: Container(
              width: 150,
              height: 150,
              child: Image.asset("assets/flutter_2.png")),
        ),
      ),
    );
  }
}

Any solution for this ? Thanks in Advance :)

1 Answers

Write this:

AnimationController _animationController = AnimationController();

You need to instantiate it AnimationController first, then call it, like you would do with TextEditingControllerd and other controllers in general.

Related