Home > Software design >  I'm creating and validating a dynamic form in Flutter, but when I change the page and return to
I'm creating and validating a dynamic form in Flutter, but when I change the page and return to

Time:05-10

It works in release mode but I get an error in debug mode

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

**Error Message **

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'

enter image description here

enter image description here

CodePudding user response:

I hope this could help you to solve your problem

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