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!
For Android, go to "Settings" - "Apps" - select your test app - "Permissions" - then turn "on" the slider for contacts.
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';
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With