You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter实现安卓/iOS端直接跳转对应应用商店指定页面的方法

在Flutter中直接打开对应平台的应用商店指定页面

嘿,我刚好踩过这个坑!不用自己写原生桥接代码那么麻烦,Flutter社区有现成的工具能帮你一键搞定,而且完美适配安卓和iOS,直接唤起官方应用商店而非浏览器。

步骤1:引入依赖

首先在你的pubspec.yaml里添加url_launcher包——这是Flutter官方推荐的URL跳转工具,能处理各种平台的scheme跳转:

dependencies:
  flutter:
    sdk: flutter
  url_launcher: ^6.2.0 # 建议用pub上的最新版本

然后执行flutter pub get拉取依赖。

步骤2:实现核心跳转逻辑

接下来写一个方法,自动判断当前平台,构造对应的应用商店跳转链接,然后唤起应用:

import 'package:flutter/foundation.dart';
import 'package:url_launcher/url_launcher.dart';

Future<void> openTargetAppStorePage() async {
  String targetUrl;
  // 根据平台构造不同的跳转链接
  if (defaultTargetPlatform == TargetPlatform.android) {
    // 安卓用你熟悉的market:// scheme,替换成你的应用包名
    targetUrl = 'market://details?id=com.your.app.package.name';
  } else if (defaultTargetPlatform == TargetPlatform.iOS) {
    // iOS用itms-apps:// scheme,替换成你的App Store应用ID(在App Store Connect里能找到)
    targetUrl = 'itms-apps://apps.apple.com/cn/app/你的应用名称/id1234567890';
    // 也可以用更通用的https链接,但itms-apps会直接唤起App Store应用,体验更好
  } else {
    // 其他平台(比如Web、桌面)可以 fallback 到应用商店的网页版
    targetUrl = 'https://play.google.com/store/apps/details?id=com.your.app.package.name';
  }

  final uri = Uri.parse(targetUrl);
  if (await canLaunchUrl(uri)) {
    // 用externalApplication模式确保打开外部应用(应用商店),而非WebView
    await launchUrl(uri, mode: LaunchMode.externalApplication);
  } else {
    throw '无法打开目标应用商店页面,请检查链接是否正确';
  }
}

额外注意事项

针对Android 11+版本

如果你的应用需要适配Android 11及以上版本,记得在android/app/src/main/AndroidManifest.xml的<manifest>标签内添加以下查询配置,否则系统会限制唤起Play Store:

<queries>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="market" />
  </intent>
</queries>

针对iOS版本

iOS这边不需要额外配置,itms-apps://是系统原生支持的scheme,直接使用即可,调用方法后会直接唤起App Store应用的指定页面。

这样调用openTargetAppStorePage()方法,就能在安卓上直接唤起Play Store的应用详情页,iOS上唤起App Store,完全满足你的需求!

内容的提问来源于stack exchange,提问作者GreenTigerEye

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:20:06