EmailMlValidator class
ML-powered email typo detector using an on-device TFLite model.
Runs a char-level classification model that predicts whether an email domain is valid or a typo, and suggests the most likely correction.
Falls back to edit-distance detection when the model isn't available.
To use this, you need to:
- Train a char-level model (see the example training script)
- Export it as a TFLite model
- Bundle it in your app's assets
final validator = EmailMlValidator(
modelAsset: 'assets/models/email_typo.tflite',
labels: ['gmail.com', 'yahoo.com', 'outlook.com', ...],
);
await validator.initialize();
SmartTextFormField(
name: 'email',
asyncValidator: validator.asAsyncValidator(
fallbackValidator: SmartValidators.email(),
),
)
- Inheritance
-
- Object
- MlValidator
- EmailMlValidator
Constructors
-
EmailMlValidator({required String modelAsset, required List<
String> labels, double confidenceThreshold = 0.7, int maxLength = 64, EmailTypoDetector? fallbackDetector, ModelLoader? loader})
Properties
- confidenceThreshold → double
-
Minimum confidence to consider a prediction valid.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isReady → bool
-
Whether the model has been loaded and is ready for inference.
no setterinherited
-
labels
→ List<
String> -
The ordered list of domain labels the model was trained on.
Index 0 = "valid/unknown", remaining indices map to known domains.
final
- modelAsset → String
-
finalinherited
- preprocessor → TextPreprocessor
-
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
asAsyncValidator(
{String? fallbackValidator(String?)?}) → Future< String?> Function(String?) -
Creates a validator function compatible with SmartTextFormField.
inherited
-
dispose(
) → void -
Releases the model resources.
inherited
-
initialize(
) → Future< void> -
Loads the model. Must be called before validate.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
postprocess(
List rawOutput, String input) → MlValidationResult -
Interprets model output into a validation result.
override
-
preprocess(
String input) → List< List< double> > -
Converts input text into the model's expected input tensor format.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
String input) → Future< MlValidationResult> -
Runs the model on
inputand returns a validation result.inherited -
validateEmail(
String email) → Future< MlValidationResult> - Validates an email using the ML model, with edit-distance fallback.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited