Flutter TextFormField onSave() doesn't get called after successful validation

The onSaved() function won't be called automatically after successful validation. We have to call _formKey.currentState.save() manually to save our variables.

Form(
  key: key,
  child: TextFormField(
    onSaved: (val) {
      print('saved');
    },
    validator: (val) {
      print('validating');
    },
  ),
),
RaisedButton(
  child: Text('Click me'),
  onPressed: () {
    if (key.currentState.validate()) {
      key.currentState.save();
      print('valid');
    }
  },
),

Tags:

Dart

Flutter