簡體   English   中英

在 Flutter 中使用 URL Launcher 時出錯

[英]Error while using URL Launcher in Flutter

onTap: () async {
  final url = products[index].url;

  if (!await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }

錯誤:

I/UrlLauncher(20613): component name for https://www.crucial.in/products/memory/desktop-dram is {com.android.chrome/com.google.android.apps.chrome.IntentDispatcher}
E/flutter (20613): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Could not launch https://www.crucial.in/products/memory/desktop-dram
E/flutter (20613): #0      HomeScreen.build.<anonymous closure>.<anonymous closure>
package:crucial/screens/home_screen.dart:52
E/flutter (20613): <asynchronous suspension>

將此添加到您的 android 清單文件中:

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>

並使用這個:

Future<void>_launchURL(String link) async {
  if (await canLaunchUrl(Uri.parse(link))) {
    await launchUrl(Uri.parse(link));
  } else {
    throw 'Could not launch $link';
  }
}

適合我

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM