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

实现按钮点击触发应用评分弹窗并跳转Google Play Store

实现带引导弹窗的Google Play应用评分功能

先看目标弹窗样式:
目标评分弹窗样式

以下是基于你现有代码改造的实现方案:

1. 依赖准备

确保pubspec.yaml中添加url_launcher依赖:

dependencies:
  flutter:
    sdk: flutter
  url_launcher: ^6.2.5 # 可替换为最新版本

2. 完整实现代码

替换你原有的onPressed逻辑,改为点击按钮时弹出弹窗:

onPressed: () => _showRatingDialog(context),

弹窗实现方法:

Future<void> _showRatingDialog(BuildContext context) async {
  const String packageName = 'com.mycompany.refereevision'; // 替换为你的应用包名
  const String url = 'https://play.google.com/store/apps/details?id=$packageName';

  return showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: const Text('给我们评分吧!'),
        content: const Text('如果您喜欢这款应用,欢迎前往Google Play为我们打分,您的支持是我们前进的动力!'),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(context),
            child: const Text('以后再说'),
          ),
          TextButton(
            onPressed: () async {
              Navigator.pop(context);
              if (await canLaunchUrl(Uri.parse(url))) {
                await launchUrl(Uri.parse(url));
              } else {
                throw '无法打开Google Play链接';
              }
            },
            child: const Text('去评分'),
          ),
        ],
      );
    },
  );
}

3. 代码说明

  • 点击按钮触发_showRatingDialog方法弹出弹窗
  • 弹窗包含标题、引导文本及两个操作按钮
  • “去评分”按钮点击后关闭弹窗,执行原有Google Play跳转逻辑
  • “以后再说”按钮直接关闭弹窗,不执行跳转

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 17:47:09