CallDetector constructor

CallDetector()

CallDetector is a singleton class designed for detecting and monitoring phone call status on the platform.

It provides a single access point to a stream of call state events, along with methods to retrieve the current call status.

CallDetector encapsulates the logic for interacting with native platforms to obtain call-related information. It uses MethodChannel to invoke native methods, and EventChannel to receive streaming updates about the call status. This class is implemented as a singleton to ensure only one instance of the detector exists throughout the app’s lifecycle, preventing resource duplication and conflicts.

Example usage:

final callDetector = CallDetector();
callDetector.callDetectStream.listen((isCalling) {
  if (isCalling) {
    print('Active call detected!');
  } else {
    print('Call ended or not active.');
  }
});

Implementation

factory CallDetector() => _instance;