草庐IT

android - 错误 : The class 'SingleTickerProviderStateMixin' can't be used as a mixin because it extends a class other than Object

coder 2023-05-09 原文

刚学flutter动画。使用 SingleTickerProviderStateMixin IDE 给我这个错误:

The class 'SingleTickerProviderStateMixin' can't be used as a mixin because it extends a class other than 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();
    }
  }

我的代码有什么问题?

最佳答案

添加到 analysis_options.yaml

analyzer:
  language:
    enableSuperMixins: true

另见 https://github.com/flutter/flutter/blob/master/analysis_options.yaml#L24

关于android - 错误 : The class 'SingleTickerProviderStateMixin' can't be used as a mixin because it extends a class other than Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51346911/

有关android - 错误 : The class 'SingleTickerProviderStateMixin' can't be used as a mixin because it extends a class other than Object的更多相关文章

随机推荐