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

PlatformAndroid

Allow end a call from flutter

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_phone_call_handler/flutter_phone_call_handler.dart';
import 'package:telephony/telephony.dart';
import 'package:url_launcher/url_launcher.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 _flutterPhoneCallHandlerPlugin = FlutterPhoneCallHandler();

  final testPhoneNumber = '0393067227';
  var calling = false;

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

  init() async {
    await _flutterPhoneCallHandlerPlugin.requestPermissions();
  }

  startCall() async {
    final Telephony telephony = Telephony.instance;
    await telephony.dialPhoneNumber(testPhoneNumber);
  }

  Future<void> endCall() async {
    try {
      var success = await _flutterPhoneCallHandlerPlugin.endCall();
    } on PlatformException {
      print("Failed to end call");
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              if (calling) {
                endCall();
              } else {
                startCall();
              }
              setState(() {
                calling = !calling;
              });
            },
            child: Text(calling ? 'End' : 'Call'),
          ),
        ),
      ),
    );
  }
}
0
likes
140
pub points
51%
popularity

Publisher

unverified uploader

Allow end a call from flutter

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_phone_call_handler