flutter_otp_autofill 0.0.1 copy "flutter_otp_autofill: ^0.0.1" to clipboard
flutter_otp_autofill: ^0.0.1 copied to clipboard

A production-ready Flutter plugin for secure OTP (One-Time Password) autofill on Android and iOS without SMS read permissions.

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_otp_autofill/flutter_otp_autofill.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _otpCode = "";
  String _appSignature = "Unknown";

  @override
  void initState() {
    super.initState();
    _getAppSignature();
  }

  Future<void> _getAppSignature() async {
    String? signature;
    try {
      if (Platform.isAndroid) {
        signature = await FlutterOtpAutoFill.getAppSignature();
      }
    } on PlatformException {
      signature = 'Failed to get app signature.';
    }

    if (!mounted) return;

    if (signature != null) {
      setState(() {
        _appSignature = signature!;
      });
      print("App Signature: $signature");
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Flutter OTP Autofill')),
        body: Padding(
          padding: const EdgeInsets.all(40.0),
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                const Text(
                  "Enter OTP Code",
                  style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 20),
                OtpTextField(
                  length: 6,
                  autoFocus: true,
                  onChanged: (code) {
                    setState(() {
                      _otpCode = code;
                    });
                  },
                  onCompleted: (code) {
                    setState(() {
                      _otpCode = code;
                    });
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text("OTP Completed: $code")),
                    );
                    print("OTP Completed: $code");
                  },
                ),
                const SizedBox(height: 40),
                Text(
                  "Current Code: $_otpCode",
                  style: const TextStyle(fontSize: 16),
                ),
                const SizedBox(height: 40),
                if (Platform.isAndroid) ...[
                  const Divider(),
                  const Text(
                    "Android SMS Retriever",
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                  const SizedBox(height: 10),
                  Text(
                    "App Signature: $_appSignature",
                    textAlign: TextAlign.center,
                    style: const TextStyle(color: Colors.grey, fontSize: 12),
                  ),
                  const SizedBox(height: 10),
                  const Text(
                    "Send an SMS with this format:",
                    style: TextStyle(fontSize: 12),
                  ),
                  Container(
                    padding: const EdgeInsets.all(10),
                    margin: const EdgeInsets.only(top: 5),
                    color: Colors.grey[200],
                    child: Text(
                      "<#> Your code is 123456\n$_appSignature",
                      style: const TextStyle(
                        fontFamily: 'monospace',
                        fontSize: 12,
                      ),
                    ),
                  ),
                ],
              ],
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
160
points
114
downloads

Publisher

unverified uploader

Weekly Downloads

A production-ready Flutter plugin for secure OTP (One-Time Password) autofill on Android and iOS without SMS read permissions.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_otp_autofill

Packages that implement flutter_otp_autofill