Mobile OTP Login

Mobile Number with OTP Login functionality is provided in that package.

  • Mobile Number digits length should be 10.
  • OTP digits length should be 6.
  • baseUrl & apiEndPoint is required for mobile validating api call.
  • baseUrl & apiEndPoint is required for OTP verifying api call & it will return you a response on success.

Installation

  1. Add the latest version of package to your pubspec.yaml (and run flutter pub get package_name or dart pub get package_name)

dependencies: mobile_otp: ^0.0.1

  1. Import the package and use it in your Flutter App.

    import 'pacakge:mobile_otp/view/mobile_number.dart' import 'pacakge:mobile_otp/view/get_otp.dart'

  2. Code Sample to Use

    async { var mobileNumber = await Get.to(MobileNumber(baseUrl,apiEndpoint)); print('mobileNumber: mobileNumber'); var otpResult = await Get.to(GetOTP(mobileNumber,baseUrl,apiEndpoint)); SharedPrefs.instance.setString("user_data",jsonEncode(otpResult)); print('otpResult: $otpResult'); Get.to(DashBoard()); }

  • GetX we have used in the project for re-direction here Get.to().
  • MobileNumber() is a widget screen & it will display a mobile number input screen to user & then call api with baseUrl + apiEndpoint with request body in below format. { 'strategy': 'local', 'phone': mobile, 'otp': '' } on success this screen will return you the mobile number.
  • GetOTP() is a widget screen & it will display a OTP input screen to user & then call api with baseUrl + apiEndpoint with request body in below format. { 'strategy': 'local', 'phone': mobile, 'otp': otp } on success this screen will return you the api response. // response generally userData information.

Libraries