Flutter 开发遇到错误:
LateInitializationError: Field 'animationStatus' has not been initialized。
原因是在初始化之前使用了它,我解决这个问题方法是为 AnimationStatus 添加了一个初始状态。
late AnimationStatus animationStatus = AnimationStatus.reverse;
有 bug 的代码:
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyApp>
with SingleTickerProviderStateMixin {
late Animation<double> animation;
late AnimationController controller;
late AnimationStatus animationStatus;
late double animationValue = 0;
@override
void initState() {
super.initState();
controller =
AnimationController(duration: const Duration(seconds: 2), vsync: this);
animation = Tween<double>(begin: 0, end: 300).animate(controller)
..addListener(() {