Email verification for Flutter Apps using DART.

Key points :

  • This package allows developers to verify that the provided Email is valid and also an existing one,
  • It is confirmed by sending an OTP to the specified email ID and verify them.

Features!

Key changes:

  • No more static methods, All the methods are based on the class instance.
  • More reliable and understandable method names.
  • Change in parameters.
  • Session name is made mandatory.
  • Additional option to set the OTP length for production servers

Steps

  • Initialize the class

EmailAuth emailAuth =  new EmailAuth(sessionName: "Sample session");
  • Pass in the remote server config if present

emailAuth.config(remoteServerConfiguration);

// remoteServerConfiguration : Signature
{
  "server": "server url",
  "serverKey": "serverKey"
}
  • Sending an otp

    Have the method wrapped in a async funtion.
void sendOtp() async {
  bool result = await emailAuth.sendOtp(
      recipientMail: _emailcontroller.value.text, otpLength: 5
      );
  }
  • Validating an otp

    Have the method wrapped in a funtion for better reusablity.
emailAuth.validateOtp(
        recipientMail: _emailcontroller.value.text,
        userOtp: _otpcontroller.value.text)

Usage template example

import 'package:email_auth/email_auth.dart';
...
Inside your stateLess / Statefull widget class
  ...
  
  // Declare the object
  EmailAuth emailAuth;

  @override
  void initState() {
    super.initState();
    // Initialize the package
    emailAuth = new EmailAuth(
      sessionName: "Sample session",
    );

    /// Configuring the remote server
    emailAuth.config(remoteServerConfiguration);
  }

  final TextEditingController _emailController = TextEditingController();
  final TextEditingController _otpController = TextEditingController();

  /// a Boolean function to verify if the Data provided is true
  bool verify() {
    print(emailAuth.validateOtp(
        recipientMail: _emailcontroller.value.text,
        userOtp: _otpcontroller.value.text));
  }

  /// a void funtion to send the OTP to the user
  /// Can also be converted into a Boolean function and render accordingly for providers
  void sendOtp() async {
    bool result = await emailAuth.sendOtp(
        recipientMail: _emailcontroller.value.text, otpLength: 5);
    if (result) {
      // using a void function because i am using a 
      // stateful widget and seting the state from here.
      setState(() {
        submitValid = true;
      });
    }
  }
  
  ...
   Widget build(BuildContext context) {
   /// have your controllers assigned to textFields or textFormFields
   ...
    body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              controller: _emailController,
            ),
            TextField(
              controller: _otpController,
            ),
          ],
        ),
      ),
      ...

Reference

PropertyTypeDescription
EmailAuthMain ClassThe main Class
EmailAuth.sessionNameStringThe sessionName of the instance
EmailAuth.configBoolean FunctionUsed to verify whether the remote server is valid
EmailAuth.sendOtpBoolean FunctionTakes care of sending OTP to the mail id provided
recipientMailparam of EmailAuth.sentOtp() methodemail ID of the recipient
otpLengthparam of EmailAuth.sentOtp() method : Defaults to 6length of the otp
EmailAuth.validateOtpBoolean FunctionTakes care of verifying the OTP entered by the user

Privacy Policy 😸

We never share the email ID's we get to any service, nor do we use them for our purposes, we regularly clean up the sent mail section, and we never save any data on our servers, we work on the main motive to be OPEN SOURCE , If so you have any queries kindly mail me at the email ID provided Always happy to answer.

⭐ If you like the package, a star to the repo will mean a lot.

Also feel free to fork the main branch and add some additional features, Will be eager to verify and add the updates.

Thankyou ❤️

Libraries

email_auth
This file contains a Class to handle the process of sending OTP There are no static methods like the previous one, and they are all instance members