Reputation: 8448
I am using url_launcher dependency to have a dial functionality on one of my icons; however, this works on Android but not IOS ?
Call launcher method would be:
_launchcaller() async
{
const url = '719-282-2224';
if (await canLaunch(url))
{
await launch(url);
}
else{
throw 'Could not launch $url';
}
}
Then I call that method on an onTap listener as below:
new GestureDetector(
onTap: _launchcaller,
child: new Icon(Icons.phone, color: Colors.blue, size: 50.0,),
),
Exception output:
[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
Could not launch tel:719-282-2224
#0 angryScreenState._launchcaller (file:///Users/ielbouyahyaouy/AndroidStudioProjects/app_firebase/flutter_app_books/lib/angryScreen.dart:103:7)
<asynchronous suspension>
#1 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#2 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
#3 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
#4 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
#5 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
#6 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
#7 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
#8 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (packag<…>
Upvotes: 5
Views: 3180
Reputation: 594
Starting from API30 (Android 11), if you want to open a URL (dial number) in your flutter app then you should do the following configurations for using url_launcher:
1- For Android:
<manifest>
<queries>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
</queries>
<application>
...
</application>
</manifest>
2- For iOS: Add the following to your info.plist file
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>http</string>
<string>tel</string>
<string>mailto</string>
</array>
Upvotes: 1
Reputation: 806
You can try this:
try {
var cellphone = '719-282-2224';
await launch('tel:$cellphone');
}catch (e){
throw 'Could not launch $e';
}
Upvotes: 1
Reputation: 2222
For ios devices to understand the url as a phone number you need to strip out the dashes. You can do it this way. It should also be prefixed by tel://
url = 'tel://719-282-2224';
url = url.replaceAll(new RegExp(r'-'), ''); // remove dashes
Upvotes: 1