flutter_otp_auto_field 1.0.3 copy "flutter_otp_auto_field: ^1.0.3" to clipboard
flutter_otp_auto_field: ^1.0.3 copied to clipboard

A complete Flutter OTP plugin that handles Android/iOS OTP autofill, retrieves the app signature hash, and offers a fully customizable OTP input field.


๐Ÿ” Flutter OTP Auto Field #

A complete OTP solution for Flutter apps โ€” auto-listen, extract, and display OTPs using Android's SMS Retriever API and iOS QuickType autofill. Includes a fully customizable OTP input field with familiar Container-style decoration support.


๐Ÿ’ก Why Use This Package? #

Unlike other packages that solve only one part of OTP autofill, flutter_otp_auto_field offers:

โœ… OTP Reading via Native APIs (Android & iOS)

โœ… App Signature Hash Generator for Android (for SMS Retriever API)

โœ… Built-in OTP Input Field with full customization

โœ… Paste-friendly & Stream-based OTP Listening

โœ… No SMS Permission Required (Safe for Play Store)


โœจ Features #

Feature Supported
Android SMS Retriever โœ…
iOS QuickType Autofill โœ…
App Signature Hash โœ…
OTP Stream Listener โœ…
Custom OTP Field Widget โœ…
Paste Support โœ…
No Permissions Needed โœ…

โš™๏ธ Installation #

Add to your pubspec.yaml:

dependencies:
  flutter_otp_auto_field: ^1.0.0

Then run:

flutter pub get

Android Configuration #

Set minimum SDK to 19 in your app-level android/app/build.gradle:

defaultConfig {
  minSdkVersion 19
}

โœ… No SMS permissions needed. โœ… Messages must include your app hash.


๐Ÿงช Usage #

1. Automatically Listen to OTPs #

OtpService().init(); // Start listening

OtpService().otpStream.listen((otp) {
  print("Received OTP: $otp");
});

2. Get App Signature Hash (for Android SMS) #

final hash = await OtpService().getAndroidAppSignature();
print('Your App Hash: $hash');

Include this hash in your OTP SMS like:

Your OTP is 123456
<#> flutter_otp_auto_field code: 123456
$hash

3. Use Built-in FlutterOtpAutoField Widget #

FlutterOtpAutoField(
  length: 6,
  autoFocus: true,
  onCompleted: (value) => print("Completed: $value"),
  decoration: BoxDecoration(
    border: Border(bottom: BorderSide(color: Colors.blue)),
    borderRadius: BorderRadius.circular(12),
  ),
)

It accepts all common customization options like boxWidth, boxHeight, textStyle, obscureText, etc.


๐Ÿ“ฑ iOS Support #

iOS autofill works with SMS messages that follow these rules:

  • Must contain the word "code" or its localized equivalent.

  • The message should contain only one numeric sequence.

  • Example:

    Your code is 123456
    

The OTP will appear in the keyboard suggestion bar automatically.


๐Ÿ–ผ Example App #

See example/lib/main.dart for a full working demo.

FlutterOtpAutoField(
  controller: myController,
  length: 6,
  onCompleted: (value) => print("OTP: $value"),
)


๐Ÿ’ฌ Paste Support #

If the user pastes OTP via the clipboard or from system suggestion, the widget handles it automatically โ€” no extra handling needed!


๐Ÿงผ Clean Architecture #

  • Uses platform channels for Android/iOS native integration
  • Proper stream management (auto-dispose & cleanup)
  • Minimal setup โ€” just init() and listen

๐Ÿ“ฆ API Reference #

Method Description
OtpService().init() Start OTP listener
OtpService().otpStream Stream of OTP values
OtpService().getAndroidAppSignature() App hash for SMS messages

๐Ÿง‘โ€๐Ÿ’ป Contributing #

Have an idea or want to improve this package? Feel free to open an issue or pull request!


๐Ÿ“„ License #

MIT License ยฉ 2025 Deepak Singh


โค๏ธ Built With Care #

This plugin was crafted to simplify OTP integration across Flutter projects โ€” combining all necessary features in one robust, lightweight package.


3
likes
150
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

A complete Flutter OTP plugin that handles Android/iOS OTP autofill, retrieves the app signature hash, and offers a fully customizable OTP input field.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_otp_auto_field

Packages that implement flutter_otp_auto_field