app_review_service.dart 936 B

1234567891011121314151617181920212223242526272829303132
  1. import 'package:flutter/material.dart';
  2. import 'package:in_app_review/in_app_review.dart';
  3. import 'package:url_launcher/url_launcher.dart';
  4. class AppReviewService {
  5. static final InAppReview _inAppReview = InAppReview.instance;
  6. // 触发评价逻辑
  7. static Future<void> requestAppReview(BuildContext context) async {
  8. try {
  9. // iOS和Android优先使用应用内评价
  10. if (await _inAppReview.isAvailable()) {
  11. await _inAppReview.requestReview();
  12. } else {
  13. await _openStoreListing();
  14. }
  15. } catch (e) {
  16. ScaffoldMessenger.of(context).showSnackBar(
  17. SnackBar(content: Text('评价功能暂时不可用,请稍后再试'))
  18. );
  19. print('Error requesting review: $e');
  20. }
  21. }
  22. // 打开应用商店列表
  23. static Future<void> _openStoreListing() async {
  24. await _inAppReview.openStoreListing(
  25. appStoreId: 'com.shishi.dingwei', // iOS应用ID
  26. );
  27. }
  28. }