Flutter Plugins : Making a phone call

When choosing plugins to achieve device related functionalities, always prefer the plugins developed by the flutter.dev author or marked as Flutter Favourite. Also you can look at the other factors like the popularity ratings, number of likes and the pub points.

While popularity ratings and likes indicate how the community is responding to the package, the pub points give an insight into the level of quality followed by the plugin/package measured by different dimensions of quality like the code style, platform support, documentation and maintainability.

Below is a sample plugin with its different parameters  indicating it being, one of the favourites in the community.

In spite of all this,sometimes we might still need to go with a less popular plugin if it is the best match for our requirement.

In this blog series  we are going to learn about using flutter plugins to use various device capabilities to achieve business functionalities. In the previous blog, we looked at using the camera plugin to implement the device camera.

In this blog, we will look at one of the most basic features of mobile phones – making phone calls. We will make use of flutter plugins to make a phone call programmatically in our app, and will explore two different scenarios of making a direct phone call or getting the intermediate dialler before the call goes through.

We have used two different plugins for this requirement:

  • the URL launcher(the popular one shown previously),
  • the flutter phone direct call.(this was the less popular and less maintained one but matched our requirement of making a direct call without any intermediate dial pad screen).

Let’s look at how we can make use of these 2 plugins to make calls in Flutter code.

We will be working on the same example from the last blog and enhance it for this feature. Alternatively, You can start by creating a new app also.

Dependencies

Add the prerequisites in the pubspec.yaml which includes the plugins identified in the process. You can pick one of these based on your requirements.

flutter_phone_direct_caller: ^1.0.1

Android -No need any additional configuration.

iOS

Add this to your info.plist

url_launcher: ^5.5.0

No additional configuration.

Creating the widget

We will create a widget which will use the plugin to showcase the call making functionality which will be included on the main screen. 

flutter_phone_direct_caller

This is one of the simplest plugins to implement which is done using the following step where contact is the phone number in String type. If you have the phone number saved as an int, you can use contact.toString() to convert to String.

This plugin will make the call directly without any intermediate step of opening the dialpad as shown below(ignore the error as I used an invalid phone number).

Url_launcher

This plugin can be used for a variety of scenarios including sending mail, sms, opening a url in the browser. This can be handled by the variation of schemes used as part of the url.

The scheme is essential, else the launch will be unsuccessful. You can try out the other schemes like mailto: , sms: for sending mails, sms.

In this case, since we need to make a phone call, the phone number to be preceded by ‘tel:’.

This plugin will prompt to open the dial pad, after which you can decide to go ahead with the call with another press of the green call icon.

The complete widget code is as below using both plugins.

You can find the complete git repository for the implementation here.

Conclusion

In this blog, we saw the steps to implement some of the simple plugins of flutter, to make a phone call with two different variations.

In the upcoming blogs of this series, we will continue to explore more from the awesome collection of Flutter plugins.

Related Posts

Leave a comment

Translate »