【发布时间】:2018-07-15 09:06:52
【问题描述】:
刚学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? -
我在这里找到了这个:sergiandreplace.com/flutter-animations-the-basics。只是运行他们的代码。但收到此错误。
-
你的链接没有这样的
with -
检查帖子中间。或使用此类搜索。 “基本示例”标题
-
我说的是
AnimationControllerOutputBody而不是_AnimationControllerOutputBodyState