Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

flutter input validation


// First Add this 4 line to create contoller

final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();

String get _email => _emailController.text;
String get _password => _passwordController.text;

//Validator

bool submitEnabled =
        _email.isNotEmpty && _password.isNotEmpty && (_password.length >= 5);
        
//*****************
// Inputs ***set as you want

TextField(
          controller: _passwordController,
           onChanged: (email) => _updateState(),
           )

TextField(
          controller: _emailController,
           onChanged: password => _updateState(),
           )
//****************

// for Button
onPressed: submitEnabled ? _submit : null,

//check textinput state every change for the enable button
 _updateState() {
    setState(() {});
  }
 
PREVIOUS NEXT
Tagged: #flutter #input #validation
ADD COMMENT
Topic
Name
4+5 =