Skip to content

Commit 85f1cb6

Browse files
committed
Add new option disableOptionalUpdates
1 parent 54e4869 commit 85f1cb6

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ The `Upgrader` class can be customized by setting parameters in the constructor,
156156
* languageCode: the language code that will override the system locale, which defaults to ```null```
157157
* messages: optional localized messages used for display in `upgrader`
158158
* minAppVersion: the minimum app version supported by this app. Earlier versions of this app will be forced to update to the current version. It should be a valid version string like this: ```2.0.13```. Overrides any minimum app version from UpgraderStore. Defaults to ```null```.
159+
* disableOptionalUpdates: If set to `true`, this flag will disable optional app updates for the current version.
160+
When disabled, only mandatory updates (those below minimum app version) will be prompted to the user. Defaults to `false`.
159161
* storeController: a controller that provides the store details for each platform, defaults to `UpgraderStoreController()`.
160162
* upgraderDevice: an abstraction of the device_info details which is used for the OS version, defaults to `UpgraderDevice()`.
161163
* upgraderOS: information on which OS this code is running on, defaults to `UpgraderOS()`.

lib/src/upgrade_state.dart

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class UpgraderState {
2323
this.languageCodeOverride,
2424
this.messages,
2525
this.minAppVersion,
26+
this.disableOptionalUpdates = false,
2627
this.packageInfo,
2728
required this.upgraderDevice,
2829
required this.upgraderOS,
@@ -62,6 +63,11 @@ class UpgraderState {
6263
/// app version from UpgraderStore. Optional.
6364
final Version? minAppVersion;
6465

66+
/// If set to `true`, this flag will disable optional app updates for the current version.
67+
/// When disabled, only mandatory updates (those below minimum app version) will be
68+
/// prompted to the user. Defaults to `false`.
69+
final bool disableOptionalUpdates;
70+
6571
/// The app package metadata information.
6672
final PackageInfo? packageInfo;
6773

@@ -87,6 +93,7 @@ class UpgraderState {
8793
String? languageCodeOverride,
8894
UpgraderMessages? messages,
8995
Version? minAppVersion,
96+
bool? disableOptionalUpdates,
9097
PackageInfo? packageInfo,
9198
UpgraderDevice? upgraderDevice,
9299
UpgraderOS? upgraderOS,
@@ -104,6 +111,7 @@ class UpgraderState {
104111
languageCodeOverride: languageCodeOverride ?? this.languageCodeOverride,
105112
messages: messages ?? this.messages,
106113
minAppVersion: minAppVersion ?? this.minAppVersion,
114+
disableOptionalUpdates: disableOptionalUpdates ?? this.disableOptionalUpdates,
107115
packageInfo: packageInfo ?? this.packageInfo,
108116
upgraderDevice: upgraderDevice ?? this.upgraderDevice,
109117
upgraderOS: upgraderOS ?? this.upgraderOS,
@@ -134,6 +142,7 @@ class UpgraderState {
134142
languageCodeOverride == true ? null : this.languageCodeOverride,
135143
messages: messages == true ? null : this.messages,
136144
minAppVersion: minAppVersion == true ? null : this.minAppVersion,
145+
disableOptionalUpdates: disableOptionalUpdates,
137146
packageInfo: packageInfo == true ? null : this.packageInfo,
138147
upgraderDevice: upgraderDevice,
139148
upgraderOS: upgraderOS,

lib/src/upgrader.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Upgrader with WidgetsBindingObserver {
5555
String? languageCode,
5656
UpgraderMessages? messages,
5757
String? minAppVersion,
58+
bool disableOptionalUpdates = false,
5859
UpgraderStoreController? storeController,
5960
UpgraderDevice? upgraderDevice,
6061
UpgraderOS? upgraderOS,
@@ -71,6 +72,7 @@ class Upgrader with WidgetsBindingObserver {
7172
messages: messages,
7273
minAppVersion:
7374
parseVersion(minAppVersion, 'minAppVersion', debugLogging),
75+
disableOptionalUpdates: disableOptionalUpdates,
7476
upgraderDevice: upgraderDevice ?? UpgraderDevice(),
7577
upgraderOS: upgraderOS ?? UpgraderOS(),
7678
),
@@ -303,7 +305,7 @@ class Upgrader with WidgetsBindingObserver {
303305
rv = false;
304306
} else if (isBlocked) {
305307
rv = true;
306-
} else if (isTooSoon() || alreadyIgnoredThisVersion()) {
308+
} else if (state.disableOptionalUpdates || isTooSoon() || alreadyIgnoredThisVersion()) {
307309
rv = false;
308310
}
309311
if (state.debugLogging) {

0 commit comments

Comments
 (0)