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

PlatformAndroid

Flutter plugin for Android Sms Retriever Api, automatically read sms from Android device.

example/lib/main.dart

import 'dart:async';

import 'package:auto_otp/auto_otp.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.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 _sms = 'Unknown';
  final _autoOtpPlugin = AutoOtp();

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

  @override
  void dispose() {
    _autoOtpPlugin.removeSmsListener();
    super.dispose();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _autoOtpPlugin.getSmsCode() ?? 'Unable to capture sms';
    } on PlatformException {
      platformVersion = 'Failed to get sms';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _sms = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Auto otp app')),
        body: Center(child: Text('Sms Status: $_sms')),
      ),
    );
  }
}
1
likes
160
points
325
downloads

Publisher

verified publishernikb.in

Weekly Downloads

Flutter plugin for Android Sms Retriever Api, automatically read sms from Android device.

Repository (GitHub)
View/report issues

Topics

#otp #sms-autofill #sms-retriever-api

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on auto_otp

Packages that implement auto_otp