我有一个有状态的小部件
class Period extends StatefulWidget{
final StreamController<List<dynamic>> notify = StreamController<List<dynamic>>();
final int period;
Period(List<dynamic> data, this.period){
notify.sink.add(data);
print("created new Period:");
print(period);
}
void dispose() {
notify.close();
}
@override
_PeriodState createState() => _PeriodState();
}
class _PeriodState extends State<Period> {
bool isNull = true;
bool isListening = false;
List<Widget> lessons;
_PeriodState(){
lessons = [(genTime())];
widget.notify.stream.listen(update);
isListening = true;
}
}
但在widget.notify.stream.listen(update);
这一行中,它捕获了异常"The getter 'notify' was called on null."。为什么widget会是null?我打印输出了包含Periods的List,但它们都已经被正确初始化了。
widget
为空? :0 - fr3ddie