在使用Flutter中的StatefulWidget时,在构造函数中必须提供一个名为vsync的命名参数。例如:
class MyWidgetState extends State
AnimationController _controller;
@override void initState() { super.initState(); _controller = AnimationController( duration: const Duration(seconds: 1), vsync: this, //必须提供vsync参数 ); }
@override Widget build(BuildContext context) { return Container(); } }
在AnimationController的构造函数中,必须提供一个vsync参数,指定此类mixin对象可用于驱动所需功能的Ticker对象。此参数通常为State对象,因此为了方便,使用with SingleTickerProviderStateMixin添加mixin,并将此State对象传递给AnimationController的vsync参数。