From eb49e62f5274bb75df1bd3622be22838d7fe8a96 Mon Sep 17 00:00:00 2001 From: minhdanh Date: Sun, 3 Nov 2024 10:37:54 +0700 Subject: [PATCH] Add attribute forceUpgrade to decide manually if an upgrade is needed --- lib/src/upgrade_alert.dart | 8 +++++++- lib/src/upgrader.dart | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/src/upgrade_alert.dart b/lib/src/upgrade_alert.dart index 2ea597c3..d9444353 100644 --- a/lib/src/upgrade_alert.dart +++ b/lib/src/upgrade_alert.dart @@ -29,6 +29,7 @@ class UpgradeAlert extends StatefulWidget { this.showIgnore = true, this.showLater = true, this.showReleaseNotes = true, + this.forceUpgrade = false, this.cupertinoButtonTextStyle, this.dialogKey, this.navigatorKey, @@ -68,6 +69,9 @@ class UpgradeAlert extends StatefulWidget { /// Hide or show release notes (default: true) final bool showReleaseNotes; + /// Force the upgrade dialog to display. + final bool forceUpgrade; + /// The text style for the cupertino dialog buttons. Used only for /// [UpgradeDialogStyle.cupertino]. Optional. final TextStyle? cupertinoButtonTextStyle; @@ -132,7 +136,9 @@ class UpgradeAlertState extends State { /// Will show the alert dialog when it should be dispalyed. void checkVersion({required BuildContext context}) { - final shouldDisplay = widget.upgrader.shouldDisplayUpgrade(); + final shouldDisplay = widget.upgrader.shouldDisplayUpgrade( + forceUpgrade: widget.forceUpgrade, + ); if (widget.upgrader.state.debugLogging) { print('upgrader: shouldDisplayReleaseNotes: $shouldDisplayReleaseNotes'); } diff --git a/lib/src/upgrader.dart b/lib/src/upgrader.dart index 27dfbbf0..8df036fd 100644 --- a/lib/src/upgrader.dart +++ b/lib/src/upgrader.dart @@ -286,7 +286,7 @@ class Upgrader with WidgetsBindingObserver { return belowMinAppVersion() || versionInfo?.isCriticalUpdate == true; } - bool shouldDisplayUpgrade() { + bool shouldDisplayUpgrade({bool forceUpgrade = false}) { final isBlocked = blocked(); if (state.debugLogging) { @@ -299,6 +299,8 @@ class Upgrader with WidgetsBindingObserver { bool rv = true; if (state.debugDisplayAlways || (state.debugDisplayOnce && !_hasAlerted)) { rv = true; + } else if (forceUpgrade) { + rv = true; } else if (!isUpdateAvailable()) { rv = false; } else if (isBlocked) {