Step 1: Install OTPLESS SDK Dependency

Install the OTPLESS SDK dependency by running the following command in your terminal at the root of your Flutter project:

flutter pub add otpless_flutter_lp:1.0.0
flutter pub get

Step 2: Platform-specific Integrations

Requirements

  • The compileSdk version should be 35.
  • The minimum SDK version supported by the SDK is 21.
  • The kotlin version should be 1.9.0 and above.
  • The gradle version should be 8.3.1 and above.
  1. Add intent filter inside your android/app/src/main/AndroidManifest.xml file into your Main activity code block:
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
      android:host="otpless"
      android:scheme= "otpless.YOUR_APP_ID_LOWERCASE"/>
</intent-filter>

Replace YOUR_APP_ID with your actual App ID provided in your OTPLESS dashboard.

  1. Add Network Security Config inside your android/app/src/main/AndroidManifest.xml file into your <application> code block (Only required if you are using the SNA feature):
android:networkSecurityConfig="@xml/otpless_network_security_config"
  1. Change your activity launchMode to singleTop and exported true for your Main Activity:
android:launchMode="singleTop"
android:exported="true"

Step 3: Configure Sign up/Sign in

  1. Import the OTPLESS package on your login page.
login_page.dart
import 'package:otpless_flutter_lp/otpless_flutter.dart';
  1. Add OTPLESS instance and declare the variable with YOUR_APP_ID
login_page.dart
  final _otplessFlutterLP = Otpless();

  
  void initState() {
    super.initState();
    _otplessFlutterLP.initialize("YOUR_APP_ID", "YOUR_SECRET");
    _otplessFlutterLP.setResponseCallback(onLoginPageResult);
  }

Replace YOUR_APP_ID with your actual App ID provided in your OTPLESS dashboard.

  1. Show the Otpless Login Page:
login_page.dart
  Future<void> openLoginPage() async {
    _otplessFlutterLP.start();
  }


  void onLoginPageResult(dynamic result) {
    final token = result['token'];
    if (token != null) {
        // Send token to your backend and validate the token to get user details
    }
  }
  1. When user successfully logs in or your login screen is destroyed, stop Otpless service:
login_page.dart
  void stopOtpless() {
    _otplessFlutterLP.stop();
  }