rating_utils.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:logging/logging.dart';
  4. import 'package:puzzleweave/l10n/app_localizations.dart';
  5. import 'package:puzzleweave/rating/rating_dialog.dart';
  6. import 'package:puzzleweave/rating/rating_helper.dart';
  7. import 'package:rate_my_app/rate_my_app.dart';
  8. final Logger _log = Logger('rating_utils');
  9. ////////////////// rate relate /////////////////////
  10. showRateDialog(BuildContext context) {
  11. _log.info("showRateDialog...");
  12. if (Platform.isIOS) {
  13. showIOSRateDialog(context);
  14. } else {
  15. showSelfRateDialog(context);
  16. }
  17. }
  18. showIOSRateDialog(BuildContext context) async {
  19. RateMyApp rateMyApp = RateMyApp(
  20. preferencesPrefix: 'rateMyApp_',
  21. minDays: 0, // Show rate popup on first day of install.
  22. minLaunches: 2, // Show rate popup after 1 launches of app after minDays is passed.
  23. googlePlayIdentifier: 'jigsort.solitaire.jigsaw.match.games',
  24. appStoreIdentifier: '6499138123',
  25. );
  26. await rateMyApp.init();
  27. if (context.mounted && rateMyApp.shouldOpenDialog) {
  28. rateMyApp.showRateDialog(context);
  29. RatingHelper.onRateSubmmit(5); // IOS跟踪不到评分,只能都写个5颗星
  30. } else {
  31. _log.info("should show iOS rate dialog but ios not allow to");
  32. }
  33. }
  34. showSelfRateDialog(BuildContext context) async {
  35. final dialog = RatingDialog(
  36. initialRating: 5.0,
  37. title: Text(
  38. AppLocalizations.of(context)!.rateUs,
  39. textAlign: TextAlign.center,
  40. style: const TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
  41. ),
  42. // encourage your user to leave a high rating?
  43. message: Text(AppLocalizations.of(context)!.rateMessage, textAlign: TextAlign.center, style: const TextStyle(fontSize: 15)),
  44. image: Image.asset("assets/icons/icon_round.png", height: 100),
  45. submitButtonText: AppLocalizations.of(context)!.submit,
  46. submitButtonTextStyle: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white),
  47. enableComment: false,
  48. onCancelled: () {
  49. RatingHelper.onRateCancel();
  50. },
  51. onSubmitted: (response) {
  52. _log.info('rating: ${response.rating}, comment: ${response.comment}');
  53. RatingHelper.onRateSubmmit(response.rating);
  54. },
  55. );
  56. showDialog(
  57. context: context,
  58. barrierDismissible: false, // set to false if you want to force a rating
  59. builder: (context) => dialog,
  60. );
  61. }