我正在 Flutter 中创建和验证动态表单,但是当我更改页面并将 return 转到上一页时,我收到错误消息。我该如何解决

I'm creating and validating a dynamic form in Flutter, but when I change the page and return to the previous page I get an error. how can i solve

它在发布模式下工作,但在调试模式下出现错误

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();
     }