Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: The class 'SingleTickerProviderStateMixin' can't be used as a mixin because it extends a class other than Object

Just learning flutter Animation. using with SingleTickerProviderStateMixin IDE giving me this error :

The class 'SingleTickerProviderStateMixin' can't be used as a mixin because it extends a class other than Object

My code:

  import 'package:flutter/material.dart';

  class AnimationControllerOutputBody extends StatefulWidget with  {
    @override
    _AnimationControllerOutputBodyState createState() =>
        new _AnimationControllerOutputBodyState();
  }

  class _AnimationControllerOutputBodyState extends State<AnimationControllerOutputBody> with SingleTickerProviderStateMixin {

    AnimationController animation;

    @override
    void initState() {
      super.initState();
      animation = new AnimationController(
        vsync: this,
        duration: new Duration(seconds: 3),
      );
      animation.addListener(() {
        this.setState(() {});
      });
    }

    @override
    Widget build(BuildContext context) {
      return new GestureDetector(
        child: new Center(
          child: new Text(
            animation.isAnimating
                ? animation.value.toStringAsFixed(3)
                : "Tap me!",
            style: new TextStyle(
              fontSize: 50.0,
            ),
          ),
        ),
        onTap: () {
          animation.forward(from: 0.0);
        },
      );
    }

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

What's my problem in code?

like image 632
Yeahia2508 Avatar asked Jul 15 '18 09:07

Yeahia2508


People also ask

What is SingleTickerProviderStateMixin?

SingleTickerProviderStateMixin is a mixin we can add to our StatelessWidget which will give us access to a Ticker . Ticker is a class that fires a callback once per animation frame. AnimationController is a class that allows us to control animations via methods like forward() , reverse() , and isAnimating .

What is a mixin Dart?

A mixin is a class with methods and properties utilized by other classes in Dart. It is a way to reuse code and write code clean. To declare a mixin, we use the mixin keyword: mixin Mixin_name{ } Mixins, in other words, are regular classes from which we can grab methods (or variables) without having to extend them.


2 Answers

Add to analysis_options.yaml

analyzer:
  language:
    enableSuperMixins: true

See also https://github.com/flutter/flutter/blob/master/analysis_options.yaml#L24

like image 129
Günter Zöchbauer Avatar answered Nov 04 '22 13:11

Günter Zöchbauer


I my case I used SingleTickerProviderStateMixin, Please just use TickerProviderStateMixin instead of SingleTickerProviderStateMixin

like image 31
Erfan Eghterafi Avatar answered Nov 04 '22 13:11

Erfan Eghterafi