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

A Flutter plugin to listen to incoming SMS messages and fetch stored messages on Android devices. This plugin allows you to receive SMS updates in real-time and retrieve SMS history for various use cases.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:smswatcher/smswatcher.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final _smsListenerPlugin = Smswatcher();

  @override
  void initState() {
    super.initState();
    Permission.sms.request();
  }
  @override
  void dispose() {
    _smsListenerPlugin.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
          floatingActionButtonLocation:
          FloatingActionButtonLocation.centerFloat,
          floatingActionButton: Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              FloatingActionButton(
                onPressed: () {
                  _smsListenerPlugin.getAllSMS();
                },
                child: const Icon(Icons.sms),
              ),
              const SizedBox(
                height: 20,
              )
            ],
          ),
          appBar: AppBar(
            title: const Text('SMS Fetching App'),
          ),
          body: SafeArea(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  SizedBox(
                    height: MediaQuery.of(context).size.height / 6,
                    child: Column(
                      children: [
                        const Text("Listening to Latest Messages", style: TextStyle(fontWeight: FontWeight.bold)),
                        StreamBuilder(
                          stream: _smsListenerPlugin.getStreamOfSMS(),
                          builder: (context, snap) => ListTile(
                            title: Text(snap.data?["sender"] ?? "NA"),
                            subtitle: Text(snap.data?["body"] ?? "NA"),
                          ),
                        ),
                      ],
                    ),
                  ),
                  const Divider(height: 1),
                  SizedBox(
                    height: MediaQuery.of(context).size.height / 1,
                    child: Column(
                      children: [
                        const Text("Listening to Latest Messages", style: TextStyle(fontWeight: FontWeight.bold)),
                        FutureBuilder(
                          future: _smsListenerPlugin.getAllSMS(),
                          builder: (context, snap) {
                            if (!snap.hasData) return const CircularProgressIndicator(); // Optional loading state
                            return Expanded(
                              child: ListView.builder(
                                itemCount: snap.data?.length ?? 0,
                                itemBuilder: (context, index) => ListTile(
                                  title: Text(snap.data?[index]["sender"] ?? "NA"),
                                  subtitle: Text(snap.data?[index]["body"] ?? "NA"),
                                ),
                              ),
                            );
                          },
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          )),
    );
  }
}
1
likes
0
points
30
downloads

Publisher

verified publishertejasgprod.online

Weekly Downloads

A Flutter plugin to listen to incoming SMS messages and fetch stored messages on Android devices. This plugin allows you to receive SMS updates in real-time and retrieve SMS history for various use cases.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on smswatcher