Search packages, repositories and app categories

Package detailsv0.3.2

flutter_otp

A Flutter package for sending and validating OTP. Four digit OTP (customizable) is sent as a SMS to the given phone number (and country code).

30-day downloads
111
Likes
85
Pub points
40

Install package

flutter pub add flutter_otp

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter package designed to simplify the process of sending and validating one-time passwords (OTPs) via SMS. It supports customizable OTP lengths, typically four digits, and integrates with phone numbers including country codes. The package streamlines user authentication flows by handling OTP generation, delivery, and verification in a secure and efficient manner. Ideal for login, registration, or account recovery workflows requiring two-factor authentication.

Use cases

  • User login with OTP
  • Account verification
  • Password reset
  • Two-factor authentication
  • Secure onboarding
  • SMS-based authentication

Key features

  • Customizable OTP length
  • SMS integration for OTP delivery
  • Support for country codes
  • Simple API for OTP validation
  • Secure OTP handling
  • Easy setup with minimal configuration

Suitable for

  • Mobile apps requiring OTP verification
  • Authentication systems
  • User registration flows
  • Security-focused applications
  • Apps using SMS-based 2FA
  • Developers seeking quick OTP implementation

Considerations

  • Relies on external SMS services
  • Limited to SMS delivery method
  • No built-in OTP expiration management
  • Requires proper error handling for failed deliveries
  • Depends on third-party SMS provider reliability
  • Not suitable for offline use

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Awesome Flutter contributions welcome Known Vulnerabilities Build Status

flutter_otp

A Flutter package for Android and iOS for sending and verifying OTP to a Phone number.

Important message for existing Users
NEW FEATURE !!

Now you can send the message to any country code passed as a parameter to the interface (sendOtp() function)

Installing

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_otp: ^0.3.2
2. Install it

You can install packages from the command line: with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_otp/flutter_otp.dart';

Functions

The important functions used in the package are :

  1. sendOtp() to send a OTP (four digit by default, but customizable):
void sendOtp(String phoneNumber, [String messageText]) {
    ...        
}

NOTE:

  1. 10 digit phoneNumber should be passed.
  2. parameter "messageText" is optional. By default the message text is "Your OTP is : XXXX". If "messageText" parameter is passed then message is sent as " XXXX".
  1. resultChecker() which takes the OTP entered by the user as a parameter. The function returns true if OTP is matched, else false is returned.
bool resultChecker(int enteredOtp) {
    ...
} 

NOTE: The OTP entered by user (say, through TextField widget or TextFormField widget etc) is to be passed as a parameter to this function.

Usage

To use this package in your application you need to have a sim card in your mobile.

Example Usage:

...
sendOtp('958347XXXX');  //Pass phone number as String

...

int enteredOtp;
TextField(
  onChanged: (val) {
    enteredOtp = val;    
  }
)

...

bool isCorrectOTP = resultChecker();
if(isCorrectOTP) {
    print('Success');
} else {
    print('Failure');
}
...

OR custom "messageText" can be passed as parameter to sendOTP

...
sendOtp('958347XXXX', 'OTP is : ');  //Pass phone number and Custom messaseText as String

...

int enteredOtp;
TextField(
  onChanged: (val) {
    enteredOtp = val;    
  }
)

...

bool isCorrectOTP = resultChecker();
if(isCorrectOTP) {
    print('Success');
} else {
    print('Failure');
}
...

Contributors

  1. Fawaz Hussain
  2. Jerin Francis

:star: the repo to show support!

More Information

Pub package Flutter documentation.

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.