flutter_otp 0.1.3 flutter_otp: ^0.1.3 copied to clipboard
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).
flutter_otp #
A Flutter package for iOS and Android for sending and verifying OTP to a Phone number.
Installing #
Use this package as a library #
- Depend on it Add this to your package's pubspec.yaml file:
dependencies:
flutter_otp: ^0.1.3
- 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.
- 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 :
- 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. This is used to customize message text. By default the message text is "Your OTP is : XXXX". If "messageText" parameter is passed then message is sent as "
- 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 #
Star 🌟 to show support!