我正在学习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();
}
}
我的代码有什么问题?
AnimationControllerOutputBody
上有一个with
? - Rémi RousseletAnimationControllerOutputBody
而不是_AnimationControllerOutputBodyState
。 - Rémi Rousselet