| 1234567891011121314151617181920212223242526272829303132 |
- import 'package:flutter/material.dart';
- import 'package:in_app_review/in_app_review.dart';
- import 'package:url_launcher/url_launcher.dart';
- class AppReviewService {
- static final InAppReview _inAppReview = InAppReview.instance;
- // 触发评价逻辑
- static Future<void> requestAppReview(BuildContext context) async {
- try {
- // iOS和Android优先使用应用内评价
- if (await _inAppReview.isAvailable()) {
- await _inAppReview.requestReview();
- } else {
- await _openStoreListing();
- }
- } catch (e) {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(content: Text('评价功能暂时不可用,请稍后再试'))
- );
- print('Error requesting review: $e');
- }
- }
- // 打开应用商店列表
- static Future<void> _openStoreListing() async {
- await _inAppReview.openStoreListing(
- appStoreId: 'com.shishi.dingwei', // iOS应用ID
- );
- }
- }
|