代码之家  ›  专栏  ›  技术社区  ›  Yeahia2508

错误:类“单列PosivRealStistMyXin”不能用作混合函数,因为它扩展了对象以外的类。

  •  3
  • Yeahia2508  · 技术社区  · 6 年前

    只是学习颤振动画。与一起使用 SingleTickerProviderStateMixin 我给我这个错误:

    类“单列PosivRealStistMyXin”不能用作混音,因为 它扩展了对象以外的类

    我的代码:

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

    我的代码有什么问题?

    1 回复  |  直到 6 年前
        1
  •  6
  •   Günter Zöchbauer    6 年前

    添加到 analysis_options.yaml

    analyzer:
      language:
        enableSuperMixins: true
    

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