Caller

A flutter plugin to handle Phone Call state and execute a Dart callback in background.

Warning

This package is under development and since I'm not keen on native Android development, there may be a lot of work to do, so any PR are welcome.


IOS Implementation

Unfortunately I'm not familiar with IOS development neither with Switf/ObjC languages, so if you wish to help any PR will be welcome.


Getting started

All you need to start using our package after installing it, is defining a callback which must be a top level function or static function, that will be called by our plugin when any incoming call events are detected.

void callerCallbackHandler(CallerEvent event, String number, int? duration)

This callback handler must accept 3 arguments:

  • CallerEvent: The event type detect by our plugin in background.

  • Number: The incoming number that is triggering the phone state call.

  • duration: An integer that will only have a value if the current CallerEvent is equal to CallerEvent.callEnded, and will contain the duration of the previous ended call in seconds.

The CallerEvent is an enum with four possible values:

Event ValueDescription
onIncomingCallReceivedTriggered when the phone is ringing
onIncomingCallAnsweredTriggered if the phone was ringing and the call was accepted by the user
callEndedCalled after the onIncomingCallAnsewered to indicate that the call is ended
onMissedCallTriggered if the phone was ringing and the user did not answer the call

Since all this process happens in background in a Dart Isolate, there's no guarantee that the current OS will call the registered callback as soon as an event is triggered or that the callback will ever be called at all, each OS handle background services with different policies. Make sure to ask user permission before calling the Caller.initialize method of our plugin. Check the example to see a simple implementation of it.

Libraries

caller