【发布时间】:2021-09-02 17:02:13
【问题描述】:
之前,我将state 实例提供给另一个这样的类
它奏效了。
class QBox{
_KeyPageState parent; // declare variable
QBox(p){
parent = p; //get state in constructor
}
}
class _KeyPageState extends State<KeyPage> {
void initState(){
super.initState();
qBox = new QBox(this); //gave state here.
}
}
但是在更新 Flutter 之后会出现这个错误。
Error: Field 'parent' should be initialized because its type '_KeyPageState' doesn't allow null.
我怎样才能避免这个错误??
【问题讨论】:
-
后期_KeyPageState父;看看这是否有效。
-
late键也很好用