email_validator_package 0.0.2 copy "email_validator_package: ^0.0.2" to clipboard
email_validator_package: ^0.0.2 copied to clipboard

A Email validator Flutter package is used to validate email addresses both in Dart and Flutter.

Email Validator Package #

email_validator_package A Flutter Email validator package is used to validate email addresses both in Dart and Flutter. It uses Regex for validation. It is purely based on Dart, with no other dependencies. I shared a complete example of a project in which I have used this email validation in Flutter. ✨

Installation #

Create a new project with the command

flutter create MyApp

Add

email_validator_package: ...

to your pubspec.yaml of your flutter project. OR run

flutter pub add email_validator_package

in your project's root directory.

In your library add the following import:

import 'package:email_validator_package/email_validator_package.dart';

For help getting started with Flutter, view the online documentation.

Usage #

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Email Validator Package',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    String email = "addweb@yopmail.com";
    String email2 = 'invalid_email@';
    bool isValidEmail = EmailValidator.validateEmail(email);
    bool isValidEmail2 = EmailValidator.validateEmail(email2);

    log("isValidEmail  $isValidEmail");
    log("isValidEmail22  $isValidEmail2");

    return Scaffold(
      appBar: AppBar(
        title: const Text("Email Validation"),
      ),
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
          child: Column(
            children: [
              Text("$isValidEmail"),
              TextFormField(
                validator: (value) {
                  /// your logic
                  if (value!.isEmpty) {
                    return "Please Enter Email";
                  } else if (EmailValidator.validateEmail(value)) {
                    return "Please Enter Valid Email";
                  }
                  return null;
                },
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  enabledBorder: OutlineInputBorder(),
                  errorBorder: OutlineInputBorder(),
                  focusedBorder: OutlineInputBorder(),
                  disabledBorder: OutlineInputBorder(),
                  focusedErrorBorder: OutlineInputBorder(),
                  hintText: 'Email Address',
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Constructor #

Basic

Parameter Default Description Required
email - User Input email. True
2
likes
160
points
30
downloads

Publisher

verified publisheraddwebsolution.com

Weekly Downloads

A Email validator Flutter package is used to validate email addresses both in Dart and Flutter.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on email_validator_package