EmailInput constructor

EmailInput({
  1. Key? key,
  2. bool enabled = true,
  3. required TextEditingController controller,
  4. BoxConstraints? constraints,
  5. String labelText = "Email",
})

Implementation

EmailInput({
  super.key,
  super.enabled,
  required this.controller,
  this.constraints,
  this.labelText = "Email",
}) : super(
        builder: (field) {
          return TextFormField(
            enabled: enabled,
            controller: controller,
            validator: (value) {
              if (value == null || value.isEmpty) {
                return 'Please enter a valid email address. Ex. testemail@hotmail.com';
              }

              var emailRegex = RegExp(r'\w+@\w+\.\w');
              if (!emailRegex.hasMatch(value)) {
                return 'Please enter email in the form "testemail@hotmail.com"';
              }

              return null;
            },
            decoration: InputDecoration(
              labelText: labelText,
              constraints: constraints,
              border: const OutlineInputBorder(),
            ),
          );
        },
      );