How to solve: The method Save isn't defined for the class State ? || Flutter/dart

Question

Asked by Mohammad a on December 16, 2021 (source).

Do you help solve this problem ? I have a problem save()

enter image description here

The method 'save' can't be unconditionally invoked because the receiver can be 'null'.

TextFormField(
  onSaved:(val){
    _authData['email'] = val.toString() ;
    print( _authData['email']);
  } ,

),
 ElevatedButton(onPressed: _submit, child: Text(_authMode == AuthMode.Login? 'Login' : 'Signup')),
//-------------------

void _submit() {
_formKey.currentState.save();

}

Answer

Question answered by Ravindra S (source).

Try to change below line ,add null check operator(!) refer null-safety here

_formKey.currentState.save();

To

_formKey.currentState!.save();

Or

_formKey.currentState?.save();
DART FLUTTER
SHARE: