Sfoglia il codice sorgente

fix:打开商店评价。

“HeShaoZe” 4 mesi fa
parent
commit
0199ce4ffb
1 ha cambiato i file con 20 aggiunte e 10 eliminazioni
  1. 20 10
      lib/utils/app_review_service.dart

+ 20 - 10
lib/utils/app_review_service.dart

@@ -4,29 +4,39 @@ import 'package:url_launcher/url_launcher.dart';
 
 class AppReviewService {
   static final InAppReview _inAppReview = InAppReview.instance;
+  static const String _appStoreId = '6743112546'; // 替换为你的App Store ID
 
   // 触发评价逻辑
   static Future<void> requestAppReview(BuildContext context) async {
     try {
-      // iOS和Android优先使用应用内评价
-      if (await _inAppReview.isAvailable()) {
+      bool isAvailable = await _inAppReview.isAvailable();
+      if (isAvailable) {
+        // 尝试显示应用内评分
         await _inAppReview.requestReview();
       } else {
-        await _openStoreListing();
+        // 不可用时直接跳转到App Store
+        await _launchAppStore();
       }
     } catch (e) {
+      // 任何错误都跳转到App Store
+      await _launchAppStore();
       ScaffoldMessenger.of(context).showSnackBar(
-          SnackBar(content: Text('评价功能暂时不可用,请稍后再试'))
+          const SnackBar(content: Text('已为您打开应用商店评价页面'))
       );
       print('Error requesting review: $e');
     }
   }
 
-  // 打开应用商店列表
-  static Future<void> _openStoreListing() async {
-    await _inAppReview.openStoreListing(
-      appStoreId: 'com.shishi.dingwei', // iOS应用ID
-    );
+  // 使用url_launcher直接打开App Store
+  static Future<void> _launchAppStore() async {
+    final url = Uri.parse('https://apps.apple.com/app/id$_appStoreId');
+    if (await canLaunchUrl(url)) {
+      await launchUrl(url, mode: LaunchMode.externalApplication);
+    }
   }
 
-}
+  // 直接打开应用商店(备用方法)
+  static Future<void> openStoreReview(BuildContext context) async {
+    await _launchAppStore();
+  }
+}