sms_retriever_plus 1.1.1 copy "sms_retriever_plus: ^1.1.1" to clipboard
sms_retriever_plus: ^1.1.1 copied to clipboard

PlatformAndroid

A Flutter plugin for Android SMS Retriever API. Automatically reads OTP/SMS messages using the SMS Retriever API.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sms_retriever_plus/sms_retriever_plus.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 _appHash = 'Loading...';
  String _status = 'Initializing...';
  final _messages = <String>[];
  bool _listening = false;

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

  Future<void> _initSmsRetriever() async {
    SmsRetrieverPlus.initialize();
    SmsRetrieverPlus.onSmsReceivedCallback = (message) {
      setState(() {
        _messages.insert(0, message);
        _status = 'SMS received!';
      });
    };

    final hash = await SmsRetrieverPlus.getSignature();
    setState(() => _appHash = hash ?? 'No hash');
    await _start();
  }

  Future<void> _start() async {
    final ok = await SmsRetrieverPlus.initSMSAPI();
    setState(() {
      _listening = ok ?? false;
      _status = ok == true
          ? 'Listening - send SMS ending with $_appHash'
          : 'Failed to start';
    });
  }

  Future<void> _stop() async {
    await SmsRetrieverPlus.stopSMSAPI();
    setState(() {
      _listening = false;
      _status = 'Stopped';
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SMS Retriever Example'),
          actions: [
            IconButton(
              icon: Icon(_listening ? Icons.stop : Icons.play_arrow),
              onPressed: _listening ? _stop : _start,
            ),
          ],
        ),
        body: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('App Hash: $_appHash'),
              const SizedBox(height: 8),
              Row(
                children: [
                  Text('Status: $_status'),
                  const SizedBox(width: 8),
                  if (_listening)
                    const SizedBox(
                      width: 16,
                      height: 16,
                      child: CircularProgressIndicator(strokeWidth: 2),
                    ),
                ],
              ),
              const SizedBox(height: 16),
              const Text('Received Messages:',
                  style: TextStyle(fontWeight: FontWeight.bold)),
              Expanded(
                child: ListView.builder(
                  itemCount: _messages.length,
                  itemBuilder: (context, index) =>
                      ListTile(title: Text(_messages[index])),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
160
points
145
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for Android SMS Retriever API. Automatically reads OTP/SMS messages using the SMS Retriever API.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on sms_retriever_plus

Packages that implement sms_retriever_plus