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

PlatformAndroid

Updated Flutter plugin to extract OTP from SMS for verification using the SMS User Consent API in Android.

example/lib/main.dart

import 'package:otp_autofill_sms_consent/otp_autofill_sms_consent.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  late final OtpAutofillSmsConsent _otpAutofillSmsConsent;
  ScaffoldMessengerState? _scaffoldMessenger;
  String? _responseText;

  String _sms = '';

  @override
  void initState() {
    super.initState();
    _otpAutofillSmsConsent = OtpAutofillSmsConsent(
      pattern: r'\d{4,}',
      onAllowed: (sms) {
        _sms = sms;
        setState(() {});
      },
      onDenied: () {
        _responseText = 'User denied!';
      },
      onPatternUnmatched: () {
        _responseText = 'OTP not found! Please try entering OTP manually.';
      },
    )..start('otpSender');
  }

  @override
  void dispose() {
    _otpAutofillSmsConsent.stop();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('OTP Autofill SMS Consent'),
        ),
        body: Builder(
          builder: (context) {
            _scaffoldMessenger ??= ScaffoldMessenger.of(context);

            return Center(
              child: Column(
                children: [
                  Text(
                    'SMS: $_sms',
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  Text(
                    'Response: $_responseText',
                  ),
                ],
              ),
            );
          },
        ),
      ),
    );
  }
}
1
likes
160
pub points
69%
popularity

Publisher

unverified uploader

Updated Flutter plugin to extract OTP from SMS for verification using the SMS User Consent API in Android.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on otp_autofill_sms_consent