larryaasen / upgrader

A Flutter package for prompting users to upgrade when there is a newer version of the app in the store.
MIT License
523 stars 258 forks source link

Do not pop the dialog when 'Update' is clicked. #416

Open hsynksahin opened 1 month ago

hsynksahin commented 1 month ago

I'm using the package without any major problems but today something strange happen.

One of my apps that's in production did got a update release today and we forcefully updated every cleint. There for user saw only the update button, can not ignore, can not deny has to update the app. The problem is when the user clicked the update button it didnt throw the link successfully. But the dialog popped and user was abel to use the old version without any problems. And the dialog didnt shown again when application re-started.

I dont know why the lauchUrl not worked, but I've overrided the onUpdate event with my own launchUrl functions so hope this wont happen again. But why the dialog is not shown again ? Why dialog popped ? Can I request a parameter like bool popDialogOnUpdate = true that programmer can set false in situations like this ?

About dialog is not being shown again, probably because I've forgot the durationUntilAlertAgain as 24 hours. That part is my mistake, but shouldn't the upgrader detect the critical update and ignore this duration ? (I've set the duration to 1 second now. Dont know if it works)

larryaasen commented 1 month ago

To better assist in analyzing this issue, please include all of the upgrader log, which can be enabled by setting debugLogging to true.

hsynksahin commented 1 month ago

I can't get that log from a release mode app so I've reverted to an older version for this, here is the builder method wraps my app :

Code details upgrader: ^10.3.0 url_launcher: ^6.2.6 ```dart class UpgraderWrapper extends StatelessWidget { const UpgraderWrapper({ super.key, required this.child, }); static bool didLog = false; final Widget child; @override Widget build(BuildContext context) => UpgradeAlert( showLater: false, showIgnore: false, showReleaseNotes: false, barrierDismissible: false, dialogStyle: Platform.isIOS ? UpgradeDialogStyle.cupertino : UpgradeDialogStyle.material, onUpdate: () { Log.info('[UpgraderAlert] Directing to update'); return true; }, onLater: () => false, onIgnore: () => false, shouldPopScope: () => false, upgrader: Upgrader( debugDisplayAlways: true, durationUntilAlertAgain: const Duration(seconds: 1), debugLogging: const bool.fromEnvironment('logUpgrader', defaultValue: false), countryCode: Localization.currentLocale(context).countryCode, languageCode: Localization.currentLocale(context).languageCode, willDisplayUpgrade: ({required display, installedVersion, versionInfo}) { if (didLog || kReleaseMode) { didLog = true; Log.info('[UpgraderAlert] Will display: $display\n' 'Installed version: $installedVersion\n' 'AppStore version: ${versionInfo?.appStoreVersion?.toString()}\n' 'Min version : ${versionInfo?.minAppVersion?.toString()}\n' 'Critical: ${versionInfo?.isCriticalUpdate?.toString()}'); } }, ), child: child, ); } ```

I've updated this code a little on the current version but the upgrader part is the same only the onUpdate button changed as I said. But the dialog is not showing still. For the log, I've tryed to filter them trough my own logs, Here is the log: (censored the links etc. they are fine)

Logs ```cmd I/flutter (17402): upgrader: instantiated I/flutter (17402): upgrader: initialize called I/flutter (17402): upgrader: build UpgradeAlert I/flutter (17402): upgrader: initializing I/flutter (17402): upgrader: operatingSystem: android, version: SNE-LX1 10.0.0.245(C432E9R1P1) I/flutter (17402): upgrader: packageInfo packageName: I/flutter (17402): upgrader: packageInfo appName: I/flutter (17402): upgrader: packageInfo version: 0.2.5 I/flutter (17402): upgrader: current locale: en_TR I/flutter (17402): upgrader: countryCode: TR I/flutter (17402): upgrader: languageCode: en I/flutter (17402): upgrader: lookupById url: I/flutter (17402): upgrader: instantiated I/flutter (17402): upgrader: build UpgradeAlert I/flutter (17402): upgrader: UpgraderPlayStore.minAppVersion: 0.2.7 I/flutter (17402): upgrader: UpgraderPlayStore: version info: appStoreListingURL: , appStoreVersion: 0.2.7, installedVersion: 0.2.5, isCriticalUpdate: null, minAppVersion: 0.2.7, releaseNotes: 0.2.7: <...> ```

also the willDisplayUpgradenot being called

IMPORTANT: this is the debugMode test I've done and the error (no dialog) im getting is not the same as I saw in the production apps.

hsynksahin commented 1 month ago

Btw, this app only uses Critical updates. We have to dont let the user use the older versions.

I've confirmed from user devices that on both Android & Ios update the dialog is shown in the first or second app start (for the first time). Then the user presses to the Update Now button and dialog pops (that should NOT pop I think). And its not forwarding to AppStore/GooglePlay. The user keeps using the old version...

Afterwards after few closing&opening the app, sometimes the dialog is shown again (even tho in that version duration is set to 24 hours, which is good). And non of the dialogs are forwarding to appstore.

If user not presses to update button and closes the app&opens again. Dialog did not shown and user keeps using the old version.

Clearly something wrong here. Need some help or I will have to write version controller from my own server which wont be healthy i think.

hsynksahin commented 1 month ago

Just realized that tha crashlytics system was telling me the app is %100 healty then after update everyone took an error that made the app %4 crash free (LOL).

Error in return: FlutterError - upgrader: initialize() not called. Must be called first.

Last 3 Stack Trace:

upgrader.dart - Line 265 Upgrader.appName + 265

upgrader.dart - Line 277 Upgrader.body + 277

upgrade_alert.dart - Line 148 UpgradeAlertState.checkVersion. + 148