Skip to content

Instantly share code, notes, and snippets.

@rapPayne
Created October 22, 2020 02:01
Show Gist options
  • Save rapPayne/9717a930be0e7190e261e7c36442c3c6 to your computer and use it in GitHub Desktop.
Save rapPayne/9717a930be0e7190e261e7c36442c3c6 to your computer and use it in GitHub Desktop.
Adding focus
String _validateEmail(String email) {
// 1
RegExp regex = RegExp(r'\w+@\w+\.\w+');
// Add the following line to set focus to the email field
if (email.isEmpty || !regex.hasMatch(email)) _emailFocusNode.requestFocus();
// 2
if (email.isEmpty)
return 'We need an email address';
else if (!regex.hasMatch(email))
// 3
return "That doesn't look like an email address";
else
// 4
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment