我已使用url_launcher软件包。
String query = Uri.encodeComponent(Utils.getSelectedStoreAddress());
var appleUrl = 'maps:q=$query';
var googleUrl = 'https://www.google.com/maps/search/?api=1&query=$query';
_launch(appleUrl);
_launch(googleUrl);
Future<void> _launch(String url) async {
await canLaunch(url)
? await launch(url)
: _showSnackBar('could_not_launch_this_app'.tr());
}
一切都没问题,直到我遇到了这个警告:
info: 'canLaunch' is deprecated and shouldn't be used. Use canLaunchUrl instead.
launchUrlString(url)
,但因为在launchUrl(...)
的情况下,插件会尽力使 URL 有效(如文档中所述),所以建议使用launchUrl(...)
。 - Rohan Taneja