showUpdateDialog static method

Future<PlayxVersionUpdateResult<bool>> showUpdateDialog({
  1. required BuildContext context,
  2. String? localVersion,
  3. String? newVersion,
  4. String? minVersion,
  5. String? googlePlayId,
  6. String? appStoreId,
  7. String country = 'us',
  8. String language = 'en',
  9. bool? forceUpdate,
  10. bool showPageOnForceUpdate = false,
  11. bool? isDismissible,
  12. UpdateNameInfoCallback? title,
  13. UpdateNameInfoCallback? description,
  14. UpdateNameInfoCallback? releaseNotesTitle,
  15. bool showReleaseNotes = false,
  16. bool showDismissButtonOnForceUpdate = true,
  17. String? updateActionTitle,
  18. String? dismissActionTitle,
  19. UpdatePressedCallback? onUpdate,
  20. UpdateCancelPressedCallback? onCancel,
  21. LaunchMode launchMode = LaunchMode.externalApplication,
  22. Widget? leading,
})

Check the version of the app on Google play store in Android Or App Store in IOS. Then shows PlayxUpdateDialog which shows material update dialog for android and Cupertino Dialog for IOS. If the app needs to force update you can show PlayxUpdatePage instead of the dialog by setting showPageOnForceUpdate : to true. Update isDismissible to set if the PlayxUpdateDialog or PlayxUpdatePage are dismissible or not if not provided it will be not dismissible on force update. check out checkVersion and PlayxUpdateDialog and PlayxUpdatePage to learn more about the parameters used. When the user clicks on update action the app open the store, If you want to override this behavior you can call onUpdate. returns PlayxVersionUpdateResult with bool on success. and returns PlayxVersionUpdateError on error which contains information about the error.

Implementation

static Future<PlayxVersionUpdateResult<bool>> showUpdateDialog({
  required BuildContext context,
  String? localVersion,
  String? newVersion,
  String? minVersion,
  String? googlePlayId,
  String? appStoreId,
  String country = 'us',
  String language = 'en',
  bool? forceUpdate,
  bool showPageOnForceUpdate = false,
  bool? isDismissible,
  UpdateNameInfoCallback? title,
  UpdateNameInfoCallback? description,
  UpdateNameInfoCallback? releaseNotesTitle,
  bool showReleaseNotes = false,
  bool showDismissButtonOnForceUpdate = true,
  String? updateActionTitle,
  String? dismissActionTitle,
  UpdatePressedCallback? onUpdate,
  UpdateCancelPressedCallback? onCancel,
  LaunchMode launchMode = LaunchMode.externalApplication,
  Widget? leading,
}) async {
  final result = await checkVersion(
    localVersion: localVersion,
    newVersion: newVersion,
    minVersion: minVersion,
    forceUpdate: forceUpdate,
    googlePlayId: googlePlayId,
    appStoreId: appStoreId,
    country: country,
    language: language,
  );

  return result.map(success: (result) {
    final info = result.data;
    if (!info.canUpdate) {
      return PlayxVersionUpdateResult.error(PlayxVersionCantUpdateError(
          currentVersion: info.localVersion, newVersion: info.newVersion));
    }

    final shouldForceUpdate = info.forceUpdate;
    final isDialogDismissible = isDismissible ?? !shouldForceUpdate;

    if (shouldForceUpdate && showPageOnForceUpdate) {
      final page = PlayxUpdatePage(
        versionUpdateInfo: info,
        title: title,
        description: description,
        releaseNotesTitle: releaseNotesTitle,
        showReleaseNotes: showReleaseNotes,
        updateActionTitle: updateActionTitle,
        dismissActionTitle: dismissActionTitle,
        showDismissButtonOnForceUpdate: showDismissButtonOnForceUpdate,
        launchMode: launchMode,
        onUpdate: onUpdate,
        onCancel: onCancel,
        leading: leading,
      );
      if (isDialogDismissible) {
        Navigator.push(
          context,
          MaterialPageRoute<void>(builder: (BuildContext context) => page),
        );
      } else {
        Navigator.pushAndRemoveUntil(
          context,
          MaterialPageRoute<void>(builder: (BuildContext context) => page),
          (route) => false,
        );
      }
    } else {
      showDialog(
        context: context,
        barrierDismissible: isDialogDismissible,
        builder: (context) => PlayxUpdateDialog(
          versionUpdateInfo: info,
          title: title,
          description: description,
          releaseNotesTitle: releaseNotesTitle,
          showReleaseNotes: showReleaseNotes,
          updateActionTitle: updateActionTitle,
          dismissActionTitle: dismissActionTitle,
          showDismissButtonOnForceUpdate: showDismissButtonOnForceUpdate,
          launchMode: launchMode,
          onUpdate: onUpdate,
          onCancel: onCancel,
          isDismissible: isDialogDismissible,
        ),
      );
    }
    return const PlayxVersionUpdateResult.success(true);
  }, error: (error) {
    return PlayxVersionUpdateResult.error(error.error);
  });
}