flutter_background_messenger 0.0.2 copy "flutter_background_messenger: ^0.0.2" to clipboard
flutter_background_messenger: ^0.0.2 copied to clipboard

PlatformAndroid

A Flutter plugin for sending SMS messages in the background on Android devices

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_background_messenger/flutter_background_messenger.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 _messenger = FlutterBackgroundMessenger();
  final _phoneController = TextEditingController();
  final _messageController = TextEditingController();
  String _status = '';

  Future<void> _sendSMS() async {
    try {
      final success = await _messenger.sendSMS(
        phoneNumber: _phoneController.text,
        message: _messageController.text,
      );
      
      setState(() {
        _status = success ? 'SMS sent successfully!' : 'Failed to send SMS';
      });
    } catch (e) {
      setState(() {
        _status = 'Error: ${e.toString()}';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SMS Background Messenger Example'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            children: [
              TextField(
                controller: _phoneController,
                decoration: const InputDecoration(
                  labelText: 'Phone Number',
                  hintText: '+1234567890',
                ),
                keyboardType: TextInputType.phone,
              ),
              const SizedBox(height: 16),
              TextField(
                controller: _messageController,
                decoration: const InputDecoration(
                  labelText: 'Message',
                  hintText: 'Enter your message',
                ),
                maxLines: 3,
              ),
              const SizedBox(height: 16),
              ElevatedButton(
                onPressed: _sendSMS,
                child: const Text('Send SMS'),
              ),
              const SizedBox(height: 16),
              Text(_status),
            ],
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    _phoneController.dispose();
    _messageController.dispose();
    super.dispose();
  }
}
5
likes
140
points
112
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for sending SMS messages in the background on Android devices

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_background_messenger