showInAppUpdateDialog static method

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

In Android: If there is an update available and the update type is allowed. It starts either flexible update or immediate update specified by PlayxAppUpdateType. If you started a flexible update you can listen to update progress from listenToFlexibleDownloadUpdate When you detect the PlayxDownloadStatus.downloaded state, you need to restart the app to install the update. Unlike with immediate updates, Google Play does not automatically trigger an app restart for a flexible update. So you need to complete the update after it's downloaded. it's also recommended to check whether your app has an update waiting to be installed on App resume. If your app has an update in the DOWNLOADED state, prompt the user to install the update. Otherwise, the update data continues to occupy the user's device storage. To check if flexible update needs to be completed call isFlexibleUpdateNeedToBeInstalled and to complete the update call completeFlexibleUpdate Check out startFlexibleUpdate and startImmediateUpdate to learn more about the result of each call. In IOS: Check the version of the app on the App Store. Then shows PlayxUpdateDialog which shows 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 app store, If you want to override this behavior you can call onIosUpdate. returns PlayxVersionUpdateResult with bool on success. and returns PlayxVersionUpdateError on error which contains information about the error.

Implementation

static Future<PlayxVersionUpdateResult<bool>> showInAppUpdateDialog({
  required BuildContext context,
  required PlayxAppUpdateType type,
  bool? forceUpdate,
  String? localVersion,
  String? newVersion,
  String? minVersion,
  String? googlePlayId,
  String? appStoreId,
  String country = 'us',
  String language = 'en',
  bool showPageOnForceUpdate = false,
  bool? isDismissible = true,
  UpdateNameInfoCallback? title,
  UpdateNameInfoCallback? description,
  UpdateNameInfoCallback? releaseNotesTitle,
  bool showReleaseNotes = false,
  bool showDismissButtonOnForceUpdate = true,
  String? updateActionTitle,
  String? dismissActionTitle,
  UpdatePressedCallback? onIosUpdate,
  UpdateCancelPressedCallback? onIosCancel,
  LaunchMode launchMode = LaunchMode.externalApplication,
  Widget? leading,
}) async {
  if (Platform.isAndroid) {
    if (type == PlayxAppUpdateType.flexible) {
      return startFlexibleUpdate();
    } else {
      return startImmediateUpdate();
    }
  } else {
    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: onIosUpdate,
          onCancel: onIosCancel,
          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: onIosUpdate,
                  onCancel: onIosCancel,
                  isDismissible: isDialogDismissible,
                ));
      }
      return const PlayxVersionUpdateResult.success(true);
    }, error: (error) {
      return PlayxVersionUpdateResult.error(error.error);
    });
  }
}