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

outdated

The main purpose is to send sms from background and headless.You can send sms whatever the phone state is in app or background or headless.

example/lib/main.dart

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  _getPermission() async => await [
        Permission.sms,
      ].request();

  Future<bool> _isPermissionGranted() async => await Permission.sms.status.isGranted;

  _sendMessage(String phoneNumber, String message, {String simSlot}) async {
    var result = await BackgroundSms.sendMessage(
        phoneNumber: "09xxxxxxxxxx", message: "Hello");
    if (result == SmsStatus.sent) {
      print("Sent");
    } else {
      print("Failed");
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Send Sms'),
        ),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.send),
          onPressed: () async {
            if (await _isPermissionGranted()) _sendMessage("09xxxxxxxxxx", "Hello");
            _getPermission();
          },
        ),
      ),
    );
  }
}
56
likes
0
pub points
92%
popularity

Publisher

verified publishermidcarry.tk

The main purpose is to send sms from background and headless.You can send sms whatever the phone state is in app or background or headless.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on background_sms