Skip to content

Commit

Permalink
Fixed deprecation warning for WillPopScope and replaced it with PopSc…
Browse files Browse the repository at this point in the history
…ope, which required the minimum Flutter SDK version to be moved up to 3.16.0 in this package. Renamed parameter canDismissDialog to barrierDismissible in `UpgradeAlert`.
  • Loading branch information
larryaasen committed Feb 24, 2024
1 parent 7a9deea commit 4cbc70d
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 40 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 10.0.0-alpha.3

- Fixed deprecation warning for WillPopScope and replaced it with PopScope, which required the minimum Flutter SDK version to be moved up to 3.16.0 in this package.
- Renamed parameter canDismissDialog to barrierDismissible in `UpgradeAlert`.

### 10.0.0

This major update changes the structure of how the internal state is maintained and how access to app stores is provided. The API has not changed for the standard use cases. However, the way in which Appcast is used has changed slightly.

This update also makes it easier to extend upgrader to support more app stores without changing upgrader. This will come into play when used on Linux and Windows, or when supporting alternate app stores on Android.

### Changes in 10.0.0
- Implemented [UpgraderState] that is used internally to replace evaluation ready.
- BREAKING: Removed Appcast configuration so that an Appcast [UpgraderStore] can be used.
- Fixed deprecation warning for WillPopScope and replaced it with PopScope, which required the minimum Flutter SDK version to be moved up to 3.16.0 in this package.
- Renamed parameter canDismissDialog to barrierDismissible in `UpgradeAlert`.

## 10.0.0-alpha.2

(README file and documentation updates)
Expand All @@ -6,7 +23,7 @@ This major update changes the structure of how the internal state is maintained

This update also makes it easier to extend upgrader to support more app stores without changing upgrader. This will come into play when used on Linux and Windows, or when supporting alternate app stores on Android.

### Changes
### Changes in 10.0.0
- Implemented [UpgraderState] that is used internally to replace evaluation ready.
- BREAKING: Removed Appcast configuration so that an Appcast [UpgraderStore] can be used.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ The card can be customized by changing the `CardTheme` on the `MaterialApp`, or

Here are the custom parameters for `UpgradeAlert`:

* canDismissDialog: can alert dialog be dismissed on tap outside of the alert dialog, which defaults to ```false``` (not used by UpgradeCard)
* barrierDismissible: used to indicate whether tapping on the barrier will dismiss the dialog, which defaults to ```false```
* cupertinoButtonTextStyle: the text style for the cupertino dialog buttons, which defaults to ```null```
* dialogStyle: the upgrade dialog style, either ```material``` or ```cupertino```, defaults to ```material```, used only by UpgradeAlert, works on Android and iOS.
* onIgnore: called when the ignore button is tapped, defaults to ```null```
* onLater: called when the later button is tapped, defaults to ```null```
* onUpdate: called when the update button is tapped, defaults to ```null```
* shouldPopScope: called when the back button is tapped, defaults to ```null```
* shouldPopScope: called to determine if the dialog blocks the current route from being popped, which defaults to ```null```
* showIgnore: hide or show Ignore button, which defaults to ```true```
* showLater: hide or show Later button, which defaults to ```true```
* showReleaseNotes: hide or show release notes, which defaults to ```true```
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
compileSdkVersion 34

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Upgrader Example',
home: UpgradeAlert(
upgrader: Upgrader(debugLogging: true),
child: Scaffold(
appBar: AppBar(title: const Text('Upgrader Example')),
body: const Center(child: Text('Checking...')),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main_custom_alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MyUpgradeAlertState extends UpgradeAlertState {
required String? title,
required String message,
required String? releaseNotes,
required bool canDismissDialog,
required bool barrierDismissible,
required UpgraderMessages messages,
}) {
showDialog(
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
55 changes: 29 additions & 26 deletions lib/src/upgrade_alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UpgradeAlert extends StatefulWidget {
UpgradeAlert({
super.key,
Upgrader? upgrader,
this.canDismissDialog = false,
this.barrierDismissible = false,
this.dialogStyle = UpgradeDialogStyle.material,
this.onIgnore,
this.onLater,
Expand All @@ -38,8 +38,9 @@ class UpgradeAlert extends StatefulWidget {
/// The upgraders used to configure the upgrade dialog.
final Upgrader upgrader;

/// Can alert dialog be dismissed on tap outside of the alert dialog. Not used by [UpgradeCard]. (default: false)
final bool canDismissDialog;
/// The `barrierDismissible` argument is used to indicate whether tapping on the
/// barrier will dismiss the dialog. (default: false)
final bool barrierDismissible;

/// The upgrade dialog style. Used only on UpgradeAlert. (default: material)
final UpgradeDialogStyle dialogStyle;
Expand All @@ -55,9 +56,7 @@ class UpgradeAlert extends StatefulWidget {
/// Return false when the default behavior should not execute.
final BoolCallback? onUpdate;

/// Called when the user taps outside of the dialog and [canDismissDialog]
/// is false. Also called when the back button is pressed. Return true for
/// the screen to be popped.
/// Called to determine if the dialog blocks the current route from being popped.
final BoolCallback? shouldPopScope;

/// Hide or show Ignore button on dialog (default: true)
Expand Down Expand Up @@ -132,7 +131,6 @@ class UpgradeAlertState extends State<UpgradeAlert> {
}

/// Will show the alert dialog when it should be dispalyed.
/// Only called by [UpgradeAlert] and not used by [UpgradeCard].
void checkVersion({required BuildContext context}) {
final shouldDisplay = widget.upgrader.shouldDisplayUpgrade();
if (widget.upgrader.state.debugLogging) {
Expand All @@ -150,7 +148,7 @@ class UpgradeAlertState extends State<UpgradeAlert> {
message: widget.upgrader.body(appMessages),
releaseNotes:
shouldDisplayReleaseNotes ? widget.upgrader.releaseNotes : null,
canDismissDialog: widget.canDismissDialog,
barrierDismissible: widget.barrierDismissible,
messages: appMessages,
);
});
Expand Down Expand Up @@ -220,7 +218,7 @@ class UpgradeAlertState extends State<UpgradeAlert> {
required String? title,
required String message,
required String? releaseNotes,
required bool canDismissDialog,
required bool barrierDismissible,
required UpgraderMessages messages,
}) {
if (widget.upgrader.state.debugLogging) {
Expand All @@ -233,30 +231,35 @@ class UpgradeAlertState extends State<UpgradeAlert> {
widget.upgrader.saveLastAlerted();

showDialog(
barrierDismissible: canDismissDialog,
barrierDismissible: barrierDismissible,
context: context,
builder: (BuildContext context) {
return WillPopScope(
onWillPop: () async => onWillPop(),
child: alertDialog(
key,
title ?? '',
message,
releaseNotes,
context,
widget.dialogStyle == UpgradeDialogStyle.cupertino,
messages,
));
return PopScope(
canPop: onCanPop(),
onPopInvoked: (didPop) {
if (widget.upgrader.state.debugLogging) {
print('upgrader: showTheDialog onPopInvoked: $didPop');
}
},
child: alertDialog(
key,
title ?? '',
message,
releaseNotes,
context,
widget.dialogStyle == UpgradeDialogStyle.cupertino,
messages,
),
);
},
);
}

/// Called when the user taps outside of the dialog and [canDismissDialog]
/// is false. Also called when the back button is pressed. Return true for
/// the screen to be popped. Defaults to false.
bool onWillPop() {
/// Determines if the dialog blocks the current route from being popped.
/// Will return the result from [shouldPopScope] if it is not null, otherwise it will return false.
bool onCanPop() {
if (widget.upgrader.state.debugLogging) {
print('upgrader: onWillPop called');
print('upgrader: onCanPop called');
}
if (widget.shouldPopScope != null) {
final should = widget.shouldPopScope!();
Expand Down
9 changes: 3 additions & 6 deletions lib/src/upgrader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ class Upgrader with WidgetsBindingObserver {
// Determine the store to be used for this app.
final store = storeController.getUpgraderStore(state.upgraderOS);
if (store == null) {
if (state.debugLogging) {
print('upgrader: updateVersionInfo found no store controller');
}
updateState(state.copyWithNull(versionInfo: null));
return null;
}
Expand Down Expand Up @@ -255,12 +258,6 @@ class Upgrader with WidgetsBindingObserver {
return versionInfo;
}

/// Android info is fetched by parsing the html of the app store page.
Future<bool?> getAndroidStoreVersion(
{String? country, String? language}) async {
return true;
}

bool verifyInit() {
if (!_initCalled) {
throw (notInitializedExceptionMessage);
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: upgrader
description: Flutter package for prompting users to upgrade when there is a newer version of the app in the store.
version: 10.0.0-alpha.2
version: 10.0.0-alpha.3
homepage: https://github.com/larryaasen/upgrader

environment:
sdk: '>=3.1.0 <4.0.0'
flutter: ">=3.13.1"
flutter: ">=3.16.0"

dependencies:
flutter:
Expand Down

0 comments on commit 4cbc70d

Please sign in to comment.