email method

String? email(
  1. String? value, {
  2. String error = 'Email inválido',
})

use to validate email fields

TextFormField(
  autovalidateMode: AutovalidateMode.onUserInteraction,
  validator: (value) => Mask.validations.email(
    value,
    error: 'your message error', // optional field
  ),
),

------------ or ------------

TextFormField(
  autovalidateMode: AutovalidateMode.onUserInteraction,
  validator: Mask.validations.email,
),

Implementation

String? email(String? value, {String error = 'Email inválido'}) {
  String emailRegex =
      r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
  if (!RegExp(emailRegex).hasMatch(value ?? "")) return error;
  return null;
}