【问题标题】:Create a button to open app from flutter web创建一个按钮以从 Flutter Web 打开应用程序
【发布时间】:2022-01-21 00:04:06
【问题描述】:

我想在 Flutter 中创建一个应用程序。 web 版本包含一个按钮,如果安装了应用程序的移动版本(如应用程序安装或打开横幅),则应根据用户平台打开 android 或 IOS 应用程序版本。

我应该如何检测web flutter中的is app installed?

更新:

我使用import 'package:universal_html/html.dart' pakage 尝试了以下代码:

window.location.href = (defaultTargetPlatform ==
                      TargetPlatform.android)
                  ? 'https://play.google.com/store/apps/details?id=com.amazon.mShop.android.shopping'
                  : 'https://apps.apple.com/us/app/amazon-shopping/id297606951'; 

但这只是打开商店。我正在寻找一种解决方案,如果已安装则直接打开应用程序。

【问题讨论】:

    标签: flutter flutter-web


    【解决方案1】:

    如果这适合您,您可以使用 URL 启动器。这样会打开 App Store 或 Play Store,用户可以下载或打开 App。

    例如,flutter 有一个包可以完成大部分工作: https://github.com/Purus/launch_review

    LaunchReview.launch(androidAppId: "yourpackagename", iOSAppId: "appid");
    

    你只需要传递你的包名并在 ios 上传递你的应用 ID

    您也可以使用 URL 启动器:

    https://pub.dev/packages/url_launcher

    代码将类似于:

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

    网址示例

    try {
      launch("market://details?id=" + appPackageName);
    } on PlatformException catch(e) {
        launch("https://play.google.com/store/apps/details?id=" + appPackageName);        
    } finally {
      launch("https://play.google.com/store/apps/details?id=" + appPackageName);        
    }
    

    注意这段代码需要修改

    另请参阅本教程以获取帮助:https://flutteragency.com/open-appstore-playstore-url-in-flutter/

    编辑:

    如果你想直接打开另一个应用程序,你可以使用这样的东西:

    https://pub.dev/packages/external_app_launcher/

    flutter pub 添加 external_app_launcher

    代码将如下所示:

     await LaunchApp.openApp(
           androidPackageName: 'net.pulsesecure.pulsesecure',
           iosUrlScheme: 'pulsesecure://',
           appStoreLink: 'itms-apps://itunes.apple.com/us/app/pulse secure/id945832041',// openStore: false
           );
    
                    // Enter the package name of the App you want to open and for iOS add the URLscheme to the Info.plist file.
                    // The `openStore` argument decides whether the app redirects to PlayStore or AppStore.
                    // For testing purpose you can enter com.instagram.android
    

    您可以在此处找到有关实施和其他设置信息的更多信息:自述文件中的https://pub.dev/packages/external_app_launcher

    【讨论】:

    • 感谢您的回复,我在使用这个包之前尝试过:import 'package:universal_html/html.dart'。但我正在寻找一种解决方案,如果已安装,则直接打开该应用程序。
    • 您好,我更新了答案以允许这样做
    • 哦,对不起,我看到你想用它来制作 Flutter Web。那么这个包就不行了
    • 很遗憾,这不适用于 Flutter Web。
    猜你喜欢
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    相关资源
    最近更新 更多