another_telephony 0.2.8 copy "another_telephony: ^0.2.8" to clipboard
another_telephony: ^0.2.8 copied to clipboard

A Flutter plugin fork from telephony to use telephony features such as fetch network info, start phone calls, send and receive SMS, and fixed for listen for incoming SMS.

example/lib/main.dart

import 'package:another_telephony/telephony.dart';
import 'package:flutter/material.dart';
import 'dart:async';

@pragma('vm:entry-point')
onBackgroundMessage(SmsMessage message) {
  debugPrint("onBackgroundMessage called");
}

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

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

class _MyAppState extends State<MyApp> {
  String _message = "";
  final telephony = Telephony.instance;

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

  onMessage(SmsMessage message) async {
    setState(() {
      _message = message.body ?? "Error reading message body.";
    });
  }

  onSendStatus(SendStatus status) {
    setState(() {
      _message = status == SendStatus.SENT ? "sent" : "delivered";
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    // 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.

    final bool? result = await telephony.requestPhoneAndSmsPermissions;

    if (result != null && result) {
      telephony.listenIncomingSms(
          onNewMessage: onMessage, onBackgroundMessage: onBackgroundMessage);
    }

    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Center(child: Text("Latest received SMS: $_message")),
          TextButton(
              onPressed: () async {
                await telephony.openDialer("123413453");
              },
              child: Text('Open Dialer'))
        ],
      ),
    ));
  }
}
37
likes
0
points
1.33k
downloads

Publisher

verified publisherthanhdt.dev

Weekly Downloads

A Flutter plugin fork from telephony to use telephony features such as fetch network info, start phone calls, send and receive SMS, and fixed for listen for incoming SMS.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, platform

More

Packages that depend on another_telephony