Skip to main content

Check for updates

PlayxVersionUpdate.checkVersion finds the latest version, compares it with the installed one and returns a PlayxVersionUpdateResult<PlayxVersionUpdateInfo>.

final result = await PlayxVersionUpdate.checkVersion(
options: PlayxUpdateOptions(country: 'us', language: 'en'),
);

result.when(
success: (info) {
if (info.canUpdate) {
// A newer version exists.
}
},
error: (error) {
// error.errorCode and error.message explain what went wrong.
},
);

The result​

Nothing is thrown: every outcome is a PlayxVersionUpdateResult, which is either a success with data or an error.

MemberMeaning
when(success:, error:)run a callback for the outcome
map, mapAsynctransform the data, or pass the error on
isSuccess, isErrorthe state
updateData, updateErrorthe data, or null; the error, or null

PlayxVersionUpdateInfo​

FieldMeaning
localVersionthe installed version
newVersionthe latest version
canUpdatetrue when newVersion is higher than localVersion
forceUpdatetrue when the update is mandatory, see Minimum version
minVersionthe minimum version that may keep running, if known
storeUrlwhere the user updates the app
releaseNoteswhat's new, if the store provides it
countrythe store country that was used

PlayxUpdateOptions​

All options are optional.

OptionDefaultMeaning
country, languageus, enthe store country and language used by the lookup
newVersion—use this as the latest version instead of asking the store
minVersion—the minimum version, see Minimum version
forceUpdate—true or false overrides the automatic decision
localVersion—override the installed version (useful for tests)
appIds—the app id per platform, see App ids and store URLs
storeUrls—a custom store URL per platform
versionSourcethe storewhere versions come from, see Version sources
networkOptions—retries, timeouts, headers, custom Dio, see Network and errors
enableNetworkLoggingfalselog the request, response and errors to the console

Providing the version yourself​

If you already know the latest version (from your backend, Remote Config or a test), pass it:

await PlayxVersionUpdate.checkVersion(
options: PlayxUpdateOptions(newVersion: '2.0.0', minVersion: '1.5.0'),
);

On Android the Google Play page is then not requested at all, so a store failure cannot fail the check. For anything more structured, use a version source.

Errors​

A failed check returns a PlayxVersionUpdateError. Network failures are a PlayxVersionNetworkError with a stable errorCode. See Network and errors.