showRateDialog method

Future<void> showRateDialog(
  1. BuildContext context, {
  2. String title = 'Rate this app',
  3. String message = 'If you like this app, please take a little bit of your time to review it !\nIt really helps us and it shouldn\'t take you more than one minute.',
  4. DialogContentBuilder? contentBuilder,
  5. DialogActionsBuilder? actionsBuilder,
  6. String rateButton = 'Rate',
  7. String noButton = 'No thanks',
  8. String laterButton = 'Maybe later',
  9. RateMyAppDialogButtonClickListener? listener,
  10. bool ignoreNativeDialog = false,
  11. DialogStyle dialogStyle = const DialogStyle(),
  12. VoidCallback? onDismissed,
  13. bool barrierDismissible = true,
  14. String barrierLabel = '',
  15. DialogTransition dialogTransition = const DialogTransition(),
})

Shows the rate dialog.

Implementation

Future<void> showRateDialog(
  BuildContext context, {
  String title = 'Rate this app',
  String message =
      'If you like this app, please take a little bit of your time to review it !\nIt really helps us and it shouldn\'t take you more than one minute.',
  DialogContentBuilder? contentBuilder,
  DialogActionsBuilder? actionsBuilder,
  String rateButton = 'Rate',
  String noButton = 'No thanks',
  String laterButton = 'Maybe later',
  RateMyAppDialogButtonClickListener? listener,
  bool ignoreNativeDialog = false,
  DialogStyle dialogStyle = const DialogStyle(),
  VoidCallback? onDismissed,
  bool barrierDismissible = true,
  String barrierLabel = '',
  DialogTransition dialogTransition = const DialogTransition(),
}) async {
  if (!ignoreNativeDialog &&
      ((await isNativeReviewDialogSupported) ?? false)) {
    callEvent(RateMyAppEventType.requestReview);
    await launchNativeReviewDialog();
    return;
  }

  RateMyAppDialog rateMyAppDialog = RateMyAppDialog(
    this,
    title: title,
    message: message,
    contentBuilder:
        contentBuilder ?? ((context, defaultContent) => defaultContent),
    actionsBuilder: actionsBuilder,
    rateButton: rateButton,
    noButton: noButton,
    laterButton: laterButton,
    listener: listener,
    dialogStyle: dialogStyle,
  );

  callEvent(RateMyAppEventType.dialogOpen);

  RateMyAppDialogButton? clickedButton;
  if (context.mounted) {
    // Using [showDialog()] when [TransitionType.none] to get rid of the default fading animation of [showGeneralDialog].
    clickedButton = dialogTransition.transitionType == TransitionType.none
        ? await showDialog<RateMyAppDialogButton>(
            context: context,
            builder: (context) => rateMyAppDialog,
            barrierDismissible: barrierDismissible,
          )
        : await showGeneralDialog<RateMyAppDialogButton>(
            context: context,
            barrierLabel: barrierLabel,
            transitionDuration: dialogTransition.transitionDuration,
            barrierDismissible: barrierDismissible,
            transitionBuilder: dialogTransition.customTransitionBuilder ??
                (context, animation1, animation2, child) => buildAnimations(
                      animation: animation1,
                      child: child,
                      dialogTransition: dialogTransition,
                    ),
            pageBuilder: (context, animation1, animation2) => rateMyAppDialog,
          );
  }

  if (clickedButton == null && onDismissed != null) {
    onDismissed();
  }
}