call_state_listener 1.0.0 copy "call_state_listener: ^1.0.0" to clipboard
call_state_listener: ^1.0.0 copied to clipboard

PlatformAndroid

A Flutter plugin that listens to Android call state changes such as IDLE, RINGING, and OFFHOOK via an EventChannel.

example/lib/main.dart

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

Future<void> requestPhonePermission() async {
  var status = await Permission.phone.status;
  if (!status.isGranted) {
    await Permission.phone.request();
  }
}

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

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

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

class _MyAppState extends State<MyApp> {
  String _callStatus = 'Unknown';
  StreamSubscription<String>? _subscription;

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

  Future<void> _initialize() async {
    await requestPhonePermission();
    _startListening();
  }

  void _startListening() {
    _subscription = CallStateListener.callStateStream.listen((status) {
      setState(() {
        _callStatus = status;
      });
    }, onError: (error) {
      setState(() {
        _callStatus = 'Error: $error';
      });
    });
  }

  @override
  void dispose() {
    _subscription?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Call State Listener'),
        ),
        body: Center(
          child: Text(
            'Call Status: $_callStatus',
            style: const TextStyle(fontSize: 24),
          ),
        ),
      ),
    );
  }
}
0
likes
135
points
15
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin that listens to Android call state changes such as IDLE, RINGING, and OFFHOOK via an EventChannel.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on call_state_listener

Packages that implement call_state_listener