All Projects → weblineindia → Flutter Otp Authentication

weblineindia / Flutter Otp Authentication

Licence: mit
A Flutter based OTP Authentication component, used to verify your mobile number with OTP (One Time Password) using Firebase Authentication.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Flutter Otp Authentication

Flutter orientation
A Flutter plugin for device's orientation
Stars: ✭ 39 (-50%)
Mutual labels:  flutter-plugin
Math Metrix
This is Math-Puzzle game made in flutter and available on Playstore & AppStore
Stars: ✭ 48 (-38.46%)
Mutual labels:  flutter-plugin
Flutter appavailability
A Flutter plugin that allows you to check if an app is installed/enabled, launch an app and get the list of installed apps.
Stars: ✭ 63 (-19.23%)
Mutual labels:  flutter-plugin
Localize and translate
Flutter localization in easy steps, really simple
Stars: ✭ 40 (-48.72%)
Mutual labels:  flutter-plugin
Firebase auth ui
Flutter plugin for Firebase Auth UI. Supports popular auth providers by using native SDK for Android and iOS.
Stars: ✭ 44 (-43.59%)
Mutual labels:  flutter-plugin
Simple firebase auth
Simple Firebase Login Flow in Flutter
Stars: ✭ 58 (-25.64%)
Mutual labels:  firebase-authentication
Leancloud flutter plugin
LeanCloud flutter plugin by Luna Gao
Stars: ✭ 34 (-56.41%)
Mutual labels:  flutter-plugin
Firebaseauth Android
Firebase Authentication code guideline for Android developer
Stars: ✭ 67 (-14.1%)
Mutual labels:  firebase-authentication
Dlna Dart
A simple DLNA DMC library implemented by Dart.
Stars: ✭ 46 (-41.03%)
Mutual labels:  flutter-plugin
Flutter native ads
Show AdMob Native Ads use PlatformView
Stars: ✭ 63 (-19.23%)
Mutual labels:  flutter-plugin
Flutter wechat ble
ble 4.0 with wechat style api for flutter. flutter版微信api风格的低功耗蓝牙
Stars: ✭ 41 (-47.44%)
Mutual labels:  flutter-plugin
Flutter branch sdk
Flutter Plugin for create deep link using Brach Metrics SDK. This plugin provides a cross-platform (iOS, Android).
Stars: ✭ 43 (-44.87%)
Mutual labels:  flutter-plugin
Flutterradioplayer
Flutter Radio Player, A Plugin to handle streaming audio without a hassle
Stars: ✭ 59 (-24.36%)
Mutual labels:  flutter-plugin
Whatsup
**Deprecated** Real time chat app written in Swift 4 using Firebase and OTP Authentication
Stars: ✭ 39 (-50%)
Mutual labels:  firebase-authentication
Stereo
A Flutter plugin for playing music on iOS and Android.
Stars: ✭ 66 (-15.38%)
Mutual labels:  flutter-plugin
Flutter Contacts Plugin
Contact plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to read, create and update contacts from the address book.
Stars: ✭ 38 (-51.28%)
Mutual labels:  flutter-plugin
Firebase Admin Node
Firebase Admin Node.js SDK
Stars: ✭ 1,050 (+1246.15%)
Mutual labels:  firebase-authentication
Flutter install plugin
A flutter plugin for install apk for android; and using url to go to app store for iOS.
Stars: ✭ 71 (-8.97%)
Mutual labels:  flutter-plugin
Flutter Permission Handler
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
Stars: ✭ 1,144 (+1366.67%)
Mutual labels:  flutter-plugin
Flutter svg
SVG parsing, rendering, and widget library for Flutter
Stars: ✭ 1,113 (+1326.92%)
Mutual labels:  flutter-plugin

Flutter - OTP Authentication

A Flutter based OTP Authentication component, used to verify your mobile number with OTP (One Time Password) using Firebase Authentication.

Table of contents

Flutter Support

Version - Flutter 1.17 (stable)

We have tested our program in above version, however you can use it in other versions as well.

Demo


Features

  • Select country with flag & country code.
  • Verify mobile number with OTP all over the world.

Getting started

  • Download this sample project and import widget dart files in your Flutter App.
  • Update Widgets UI based on your requirements.

Usage

Setup process is described below to integrate in sample project.

Methods

Configure Country Picker Widget & implement method for call back selected country details e.g

// Put CountryPicker Widget
CountryPicker(
    callBackFunction: _callBackFunction
);
   
// Create callback function 
void _callBackFunction(String name, String dialCode, String flag) {
    // place your code
}

Configure PINEntryTextField For OTP (One Time Password)

// add this package in pubspec.yaml file
pin_entry_text_field: ^0.1.4
   
// run this command to install package
flutter pub get
   
// add PINEntryTextField in class
PinEntryTextField(
  fields: 6,
  onSubmit: (text) {
  },
)

Validate Phone Number & Generate Otp

// generate otp method and store Verification Id
Future<void> generateOtp(String contact) async {
  final PhoneCodeSent smsOTPSent = (String verId, [int forceCodeResend]) {
    verificationId = verId;
  };
  try {
    await _auth.verifyPhoneNumber(
        phoneNumber: contact,
        codeAutoRetrievalTimeout: (String verId) {
          verificationId = verId;
        },
        codeSent: smsOTPSent,
        timeout: const Duration(seconds: 60),
        verificationCompleted: (AuthCredential phoneAuthCredential) {},
        verificationFailed: (AuthException exception) {
         // Navigator.pop(context, exception.message);
        });
  } catch (e) {
    Navigator.pop(context, (e as PlatformException).message);
  }
}

Verify otp

//Method for verify otp entered by user  
Future<void> verifyOtp() async {
  if (smsOTP == null || smsOTP == '') {
    showAlertDialog(context, 'please enter 6 digit otp');
    return;
  }
  try {
    final AuthCredential credential = PhoneAuthProvider.getCredential(
      verificationId: verificationId,
      smsCode: smsOTP,
    );
    final AuthResult user = await _auth.signInWithCredential(credential);
    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.user.uid == currentUser.uid);
    Navigator.pushReplacementNamed(context, '/homeScreen');
  } catch (e) {
    handleError(e as PlatformException);
  }
}

Handle errors

//Method for handle the errors
void handleError(PlatformException error) {
  switch (error.code) {
    case 'ERROR_INVALID_VERIFICATION_CODE':
      FocusScope.of(context).requestFocus(FocusNode());
      setState(() {
        errorMessage = 'Invalid Code';
      });
      showAlertDialog(context, 'Invalid Code');
      break;
    default:
      showAlertDialog(context, error.message);
      break;
  }
}

Directive options

Firebase project setup steps

Create Project setup in firebase console using below URL https://console.firebase.google.com/ . Enable Phone Number sign-in for your Firebase project in console https://firebase.google.com/docs/auth/ios/phone-auth

Download GoogleService-Info.Plist file and add into iOS folder

Download GoogleService.json file and add into Android folder

Firebase project setup steps

Install following pub dev package

firebase_auth: ^0.15.4


Want to Contribute?

  • Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).
  • Fork it.
  • Create new branch to contribute your changes.
  • Commit all your changes to your branch.
  • Submit a pull request.

Collection of Components

We have built many other components and free resources for software development in various programming languages. Kindly click here to view our Free Resources for Software Development.


Changelog

Detailed changes for each release are documented in CHANGELOG.

License

MIT

Keywords

Flutter-OTP-Authentication, Firebase-OTP-Authentication, Firebase-Authentication, Firebase, Authentication, OTP-Authetication

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].