它在发布模式下工作,但在调试模式下出现错误
class UrunHizmetWidget extends StatefulWidget {
int index;
final state = _UrunHizmetWidgetState();
UrunHizmetWidget({Key? key, this.index = 0}) : super(key: key);
@override
State<UrunHizmetWidget> createState() => state;
bool isvalid() => state.validator();
}
**错误信息**
The following assertion was thrown building NotificationListener<KeepAliveNotification>:
The createState function for UrunHizmetWidget returned an old or invalid state instance: UrunHizmetWidget, which is not null, violating the contract for createState.
'package:flutter/src/widgets/framework.dart':
package:flutter/…/widgets/framework.dart:1
Failed assertion: line 4860 pos 7: 'state._widget == null'
我希望这能帮助你解决你的问题
class UrunHizmetWidget extends StatefulWidget {
int index;
var state = _UrunHizmetWidgetState();
UrunHizmetWidget ({Key key, this.site, this.index=0}) : super(key: key);
@override
State<UrunHizmetWidget> createState(){
return this.state=new __UrunHizmetWidgetState();
};
bool isvalid() => state.validator();
}