EmailElement constructor

EmailElement({
  1. String? id,
  2. String? initValue,
  3. String? label,
  4. String? hint,
  5. DecorationElement? decorationElement,
  6. String errorEmailPattern = "invalid email",
  7. String errorEmailIsRequired = "email is empty",
  8. bool isRequired = false,
  9. bool readOnly = false,
  10. EdgeInsets padding = const EdgeInsets.all(2.0),
  11. bool visibility = true,
})

Implementation

EmailElement({
  String? id,
  this.initValue,
  this.label,
  this.hint,
  this.decorationElement,
  this.errorEmailPattern = "invalid email",
  this.errorEmailIsRequired = "email is empty",
  this.isRequired = false,
  this.readOnly = false,
  this.padding = const EdgeInsets.all(2.0),
  bool visibility = true,
}) : super(
        id: id,
        initValue: initValue,
        label: label,
        typeInput: TypeInput.Email,
        hint: hint,
        decorationElement: decorationElement,
        padding: padding,
        readOnly: readOnly,
        validator: (email) {
          if (isRequired) {
            if (email!.isEmpty) {
              return errorEmailIsRequired;
            }
          }
          if (email!.isNotEmpty) {
            bool emailValid = RegExp(Patterns.emailPattern).hasMatch(email);
            if (!emailValid) {
              return errorEmailPattern;
            }
          }
          return null;
        },
        visibility: visibility,
      );