Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dial the phone from Flutter?

Tags:

flutter

I am building a Flutter app, and I'd like to dial a phone number in response to a button tap. What's the best way to do this?

Thanks!

like image 499
Seth Ladd Avatar asked Mar 31 '17 20:03

Seth Ladd


People also ask

How do I access contacts in Flutter phone?

For Android, go to "Settings" - "Apps" - select your test app - "Permissions" - then turn "on" the slider for contacts.


2 Answers

This method will open the dialer :

_launchCaller() async {     const url = "tel:1234567";        if (await canLaunch(url)) {        await launch(url);     } else {       throw 'Could not launch $url';     }    } 

EDIT:

In case anybody facing errors:

Add url_launcher: in the pubspec.yaml & run flutter get

Also import 'package:url_launcher/url_launcher.dart';

like image 123
Rajesh Jr. Avatar answered Nov 04 '22 16:11

Rajesh Jr.


Typically, to interact with the underlying platform, you have to write platform specific code and communicate with the same using platform channels. However, Flutter provides some points of integration with the platform out of the box. To dial the phone for instance, you can use the UrlLauncher.launch API with the tel scheme to dial the phone.

Something like UrlLauncher.launch("tel://<phone_number>"); should work fine on all platforms.

Do note that this will not work in the simulators. So make sure you are using an actual device to test this.

like image 25
Buzzy Avatar answered Nov 04 '22 17:11

Buzzy