我正在使用url_launcher依赖性在我的一个图标上具有拨号功能;但是,这可以在Android上使用,但不能在IOS上使用?
呼叫启动器方法为:
_launchcaller() async
{
const url = '719-282-2224';
if (await canLaunch(url))
{
await launch(url);
}
else{
throw 'Could not launch $url';
}
}
然后我在onTap侦听器上调用该方法,如下所示:
new GestureDetector(
onTap: _launchcaller,
child: new Icon(Icons.phone, color: Colors.blue, size: 50.0,),
),
异常输出:
[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<…>
答案 0 :(得分:0)
要使ios设备将网址理解为电话号码,您需要去除破折号。您可以通过这种方式进行。还应该以tel://
作为前缀url = 'tel://719-282-2224';
url = url.replaceAll(new RegExp(r'-'), ''); // remove dashes
答案 1 :(得分:0)
你可以试试这个:
try {
var cellphone = '719-282-2224';
await launch('tel:$cellphone');
}catch (e){
throw 'Could not launch $e';
}