in_app_update_dialog 0.0.1
in_app_update_dialog: ^0.0.1 copied to clipboard
A Flutter plugin for handling Android In-App Updates. Supports Flexible and Immediate update flows with granular control and callbacks.
in_app_update_dialog #
A Flutter plugin for handling Android In-App Updates. This plugin provides a wrapper around the Android Play Core Library, allowing you to easily implement Flexible and Immediate update flows in your Flutter application.
Features #
- Check for Updates: Query the Play Store to see if an update is available.
- Immediate Updates: Perform a blocking update that requires the user to update before proceeding.
- Flexible Updates: Perform a background update that allows the user to continue using the app while the update downloads.
- Install State Observation: Listen to the download progress and status changes (Pending, Downloading, Installed, etc.) for flexible updates.
- Complete Update: Trigger the installation once the flexible update has been downloaded.
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
in_app_update_dialog: ^0.0.1
Usage #
1. Check for Update #
First, check if an update is available.
final inAppUpdate = InAppUpdateDialog();
final info = await inAppUpdate.checkForUpdate();
if (info.updateAvailability == UpdateAvailability.updateAvailable) {
// Update is available
}
2. Immediate Update #
For critical updates, you can force an immediate update flow.
if (info.immediateUpdateAllowed) {
await inAppUpdate.startUpdate(AppUpdateType.immediate);
}
3. Flexible Update #
For optional updates, you can let the user download it in the background. You should listen to the install state to show progress or prompt the user to complete the installation when ready.
if (info.flexibleUpdateAllowed) {
// Start listening to install state changes (progress, etc.)
inAppUpdate.observeInstallState().listen((state) {
if (state.installStatus == InstallStatus.downloading) {
print("Downloaded: ${state.bytesDownloaded} / ${state.totalBytesToDownload}");
} else if (state.installStatus == InstallStatus.downloaded) {
// Prompt the user to install the update
inAppUpdate.completeUpdate();
}
});
// Start the flexible update flow
await inAppUpdate.startUpdate(AppUpdateType.flexible);
}
Api Reference #
checkForUpdate() #
Returns Future<AppUpdateInfo>. Contains information about update availability, allowed update types, and current install status.
startUpdate(AppUpdateType) #
Starts the update flow.
AppUpdateType.immediate: Full screen blocking UI.AppUpdateType.flexible: Background download.
observeInstallState() #
Returns Stream<AppInstallState>. Emits events regarding the install status (Downloading, Installed, Failed, etc.) and download progress.
completeUpdate() #
Completes a flexible update. This method should be called when the installStatus is downloaded. It typically prompts the user to restart the app to apply the update.