Simple TextFormField validator, but not return anything

you should check for the validation inside onPress Button like this

final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

FlatButton(
  onPressed: () {
    showDialog(
      context: context,
      builder: (_) => Dialog(
        child: Form(
          key: _formKey,
          child: Column(
            children: [
              TextFormField(
                key: _formKey,
                controller: roomController,
                validator: (String value) {
                  if (value.isEmpty) {
                    return 'Please create name';
                    } else if (NameList.contains(value)) {
                      return 'Existed';
                  }
                  return null;
                },
              ),
              RaisedButton(
                onPressed: () {
           if(_formKey.currentState.validate()){
           return //someting
                     }
              },
                child: Text('Create'),
              ),
            ],
          ),
        ),
      ),
    );
  },
  child: Text('Create'),
),

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top