【发布时间】:2020-01-27 08:43:41
【问题描述】:
在 Flutter 中,我正在使用“url_launcher”包,该包使用Future<bool> 来检查应用程序是否可以启动其他应用程序。在我的代码中,我列出了电话号码,并且我只想为 WhatsApp 放置一个图标,前提是它安装在用户的设备上。
bool hasWhatsApp() {
var whatsExists;
canLaunch('https://api.whatsapp.com/').then((val) => whatsExists = val);
return whatsExists;
}
我正在使用此函数检查 if 语句内部是否在屏幕上显示图标,但是,它一直返回“null”。
if (phoneNumber.substring(0, 1) != '2' && hasWhatsApp())
IconButton(
icon: Image.asset('assets/icons/whatsapp.png'),
iconSize: Theme.of(context).iconTheme.size,
onPressed: () async {
await launch(whatsUrl);
},
),
请问我该如何解决?
【问题讨论】: