Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support forcing an upgrade manually #472

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/src/upgrade_alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +136,9 @@ class UpgradeAlertState extends State<UpgradeAlert> {

/// 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');
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/upgrader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Loading