you might be getting the compilation error with below code with flutter 2.5

    if (!_formKey.currentState.validate()) {
      // Invalid!
      return;
    }
    _formKey.currentState.save();

Solution:

 final form = _formKey.currentState;
    if (form != null && !form.validate()) {
      // Invalid!
      return;
    }
    form?.save();