我正在尝试根据用户的选择启动地图应用程序。但我手机上的谷歌地图是打开的,在包含应用程序列表的底部表格打开之前。我想等到用户选择应用程序。我该如何做到这一点?
这是我打开地图的代码,如果任务类型是地址
GestureDetector(
onTap: () async {
try {
launchUrl(
Uri.parse("geo:${address.lat},${address.lng}"),
mode: LaunchMode.externalApplication,
);
} finally {
launchUrl(Uri.parse(
"google.navigation:q=${address.lat},${address.lng}&mode=d"));
}
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
CommonText(
text: kLanguageList!.value.googleMaps.obs,
size: 1,
textColor: kGreen,
boldText: false,
underline: TextDecoration.underline,
),
Image.asset(
kGoogleMapLogo,
scale: 20,
),
],
),
),
我忘记删除代码中的finally
。我认为finally block
总是执行,而不关心try block
。
GestureDetector(
onTap: () async {
launchUrl(
Uri.parse("geo:${address.lat},${address.lng}"),
mode: LaunchMode.externalApplication,
);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
CommonText(
text: kLanguageList!.value.googleMaps.obs,
size: 1,
textColor: kGreen,
boldText: false,
underline: TextDecoration.underline,
),
Image.asset(
kGoogleMapLogo,
scale: 20,
),
],
),
)
我终于卸下了,一切都很好。或者我们可以使用catch(e)
来显示错误或异常。我使用urlauncher来启动谷歌地图。