Skip to content
pubscout

otp_autofill

4.1.0, released 2 years ago by surf.ru

Android and iOS OTP autofill plugin using SMS User Consent and Retriever APIs.

$ flutter pub add otp_autofill
Source repository

What it does

It provides text editing controllers and interactors to automatically read and parse one-time passwords (OTP) from incoming SMS messages on Android and iOS. It also supports custom strategies like push notifications or testing inputs.

AI-written summary of version 4.1.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need automated SMS verification code input (OTP) for phone authentication.
  • You need to support both Android SMS Retriever/User Consent APIs and iOS native text field autofill.

Skip it when

  • You only need standard text field input without SMS auto-reading capabilities.
  • You are targeting platforms other than Android and iOS.

Strengths

  • Supports both SMS User Consent API and SMS Retriever API on Android.
  • Includes helper classes like OTPTextEditController and OTPInteractor for quick implementation.
  • Allows custom strategies (e.g., push notifications or testing).

Weaknesses

  • Requires manual setup of native minimum SDK version on Android.
  • Relies on parsing SMS text formats correctly via regular expressions.

Setup

Kind
Plugin (native code)
Effort
Low
Code generation
No
Direct dependencies
0

On Android, set minSdkVersion at least to 19 in android/app/build.gradle.

late OTPTextEditController controller;
final scaffoldKey = GlobalKey();

@override
void initState() {
  super.initState();
  controller = OTPTextEditController(
    codeLength: 5,
    onCodeReceive: (code) => print('Your Application receive code - $code'),
  )..startListenUserConsent(
      (code) {
        final exp = RegExp(r'(\d{5})');
        return exp.stringMatch(code ?? '') ?? '';
      },
    );
}

Alternatives

Packages that do the same job and could replace otp_autofill.

  • pinput

    If you need a complete customizable PIN input widget set rather than just text controller bindings.

  • pin_code_fields

    If you prefer a pin code field UI component.