网站建设合同的内容与结构,河南省建设工程造价协会网站,聚震网站开发,购物网站设计目标文章目录 问题描述问题原因解决方法 问题描述
The instance member ‘widget’ can’t be accessed in an initializer. 问题原因
“The instance member ‘widget’ can’t be accessed in an initializer” 错误是因为在初始化器列表中#xff08;constructor initializer… 文章目录 问题描述问题原因解决方法 问题描述
The instance member ‘widget’ can’t be accessed in an initializer. 问题原因
“The instance member ‘widget’ can’t be accessed in an initializer” 错误是因为在初始化器列表中constructor initializer list访问了 widget 成员。这是因为在构造函数的初始化器列表中对象的属性包括 widget还没有被初始化因此不能在这里访问它们。
有问题的源码
class CountdownTimer extends StatefulWidget {final int duration;final int numIterations;final int breakTime;const CountdownTimer({Key? key,required this.duration,required this.numIterations,required this.breakTime,}) : super(key: key);overrideStateCountdownTimer createState() _CountdownTimerState();
}class _CountdownTimerState extends StateCountdownTimer {final String countDownMusicassets/beat.mp3;final String restMusicassets/piano.mp3;late Timer _timer;double _timeProgress 1.0;double _numProgress 1.0;int rounds widget.numIterations;解决方法
int rounds widget.numIterations;这一句增加一个late修饰符
late int rounds widget.numIterations;结束语 Flutter是一个由Google开发的开源UI工具包它可以让您在不同平台上创建高质量、美观的应用程序而无需编写大量平台特定的代码。我将学习和深入研究Flutter的方方面面。从基础知识到高级技巧从UI设计到性能优化欢饮关注一起讨论学习共同进入Flutter的精彩世界