我正在使用 url_launcher: ^5.4.10 来启动不同的 url 方案,但是外部链接在 ios 模拟器上工作正常,但无法打开电话拨号盘和默认电子邮件地址,而在 android 设备上工作正常
我在ios模拟器而不是真实设备上测试它
如果我尝试在这里打开拨号盘是例外
{PTS: 6.000 s, decode: 32.021 ms},
]
flutter: could not launch tel:+18002509646
当我尝试打开邮箱时,我收到了例外
*** First throw call stack:
(
0 CoreFoundation 0x00000001084f4a2a __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00000001083874ce objc_exception_throw + 48
2 Foundation 0x0000000107f2e808 -[__NSConcreteURLComponents initWithString:] + 0
3 CoreServices 0x000000010f7c2db2 -[_LSURLOverride initWithOriginalURL:checkingForAvailableApplications:] + 136
4 CoreServices 0x000000010f7c35b5 -[_LSURLOverride initWithOriginalURL:] + 22
5 CoreServices 0x000000010f7c3d97 _ZN14LaunchServices12URLOverridesL20getURLOverrideCommonEP5NSURL + 374
6 CoreServices 0x000000010f7c3c10 -[LSApplicationWorkspace(LSURLOverride) URLOverrideForURL:] + 12
7 UIKitCore <…>
我的代码网址启动器
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
class Contactcus extends StatelessWidget {
void customLaunch(command) async {
if (await canLaunch(command)) {
await launch(command);
} else {
print(' could not launch $command');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10),
child: Container(
child: Column(
children: <Widget>[
Text(
'Contact us'.toUpperCase(),
style: TextStyle(
fontFamily: 'TT NORMS',
fontWeight: FontWeight.w100,
fontSize: 25,
),
),
Padding(
padding: EdgeInsets.only(left: 0),
child: Row(
children: <Widget>[
Expanded(
child: SizedBox(
child: ListTile(
leading: Icon(Icons.phone,
size: 25, color: Colors.black87),
onTap: () {
customLaunch('tel:+18001569647');
},
title: Text(
'Phone'.toUpperCase(),
style: TextStyle(
fontFamily: 'TT NORMS',
fontSize: 20,
fontWeight: FontWeight.w100,
),
),
subtitle: Text(
'1 (800) 250-9646 ',
style: TextStyle(
color: Colors.black87,
),
),
),
),
),
],
),
),
Padding(
padding: EdgeInsets.only(left: 0),
child: Row(
children: <Widget>[
Expanded(
child: SizedBox(
child: ListTile(
leading: Icon(Icons.email,
size: 25, color: Colors.black87),
onTap: () {
customLaunch(
'mailto:livinghopetv@cornerstoneasianchurch.com?subject=Feed%20back&body=Write your%20feedback');
},
title: Text(
'Email',
style: TextStyle(
fontFamily: 'TT NORMS',
fontWeight: FontWeight.w100,
fontSize: 20
),
),
subtitle: Text(
'livinghopetv@cornerstoneasianchurch.com',
style: TextStyle(color: Colors.black87,
),
),
),
),
),
],
),
),
Padding(
padding: EdgeInsets.only(left: 0),
child: Row(
children: <Widget>[
Expanded(
child: SizedBox(
child: ListTile(
leading: Icon(Icons.location_on,
size: 28, color: Colors.black87),
onTap:(){
customLaunch('https://www.google.ca/maps/place/3434+Cawthra+Rd,+Mississauga,+ON+L5A+2X7/@43.6025224,-79.6147441,17z/data=!3m1!4b1!4m5!3m4!1s0x882b470c94e668ff:0x62c956c363a795d9!8m2!3d43.6025185!4d-79.6125554');
},
title: Text(
'MAILING ADDRESS',
style: TextStyle(
fontFamily: 'TT NORMS',
fontWeight: FontWeight.w100,
fontSize: 20
),
),
subtitle: Text(
'Att: Living Hope TVn'
'Cornerstone Asian Churchn'
'3434 Cawthra Rdn'
'Mississauga, ON L5A 2X7n'
'Canada',
style: TextStyle(
color: Colors.black87,
),
),
),
),
),
],
),
),
Padding(
padding: EdgeInsets.only(top: 70),
child: Row(
mainAxisAlignment:MainAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Image.asset('images/youtube.png'),
iconSize: 30,
onPressed: () {
customLaunch('https://www.youtube.com/channel/UCsnohhaCJvkT3prNnMwlvnA');
},
),
IconButton(
icon: Image.asset('images/twitter.png'),
iconSize:30,
onPressed: () {
customLaunch('https://twitter.com/livinghopetv1');
},
),
IconButton(
icon: Image.asset('images/instagram.png'),
iconSize: 30,
onPressed: () {
customLaunch('https://www.instagram.com/livinghopetv/');
},
),
IconButton(
icon: Image.asset('images/facebook.png'),
iconSize: 30,
onPressed: () {
customLaunch('https://www.facebook.com/livinghopetelevision');
},
),
IconButton(
icon: Image.asset('images/web.png'),
iconSize: 30,
onPressed: () {
customLaunch('https://www.livinghopetv.org');
},
),
],
),
)
],
),
),
),
],
),
),
);
}
}
这对我有用: