๐ 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.
Would you like me to:
โ
Generate a CHANGELOG.md
โ
Create a CONTRIBUTING.md
โ
Add a GitHub Actions workflow.yml for CI
Let me know โ happy to help you polish it all for publishing on pub.dev.