错误:“ SingleTickerProviderStateMixin”类不能用作mixin,因为它扩展了Object以外的其他类

时间:2018-07-15 09:06:52

标签: android flutter

只需学习扑动动画即可。与SingleTickerProviderStateMixin IDE一起使用会给我这个错误:

  

'SingleTickerProviderStateMixin'类不能用作mixin,因为   它扩展了Object以外的其他类

我的代码:

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

我的代码有什么问题?

2 个答案:

答案 0 :(得分:6)

添加到analysis_options.yaml

analyzer:
  language:
    enableSuperMixins: true

另请参阅https://github.com/flutter/flutter/blob/master/analysis_options.yaml#L24

答案 1 :(得分:2)

我的情况我使用了 SingleTickerProviderStateMixin,请使用 TickerProviderStateMixin 而不是 SingleTickerProviderStateMixin