From c774c9b066d06c615071785aeff9f3ad0b6d3756 Mon Sep 17 00:00:00 2001 From: FredM7 Date: Mon, 28 Mar 2022 18:45:44 +0200 Subject: [PATCH 1/5] MAJOR.MINOR.PATCH+BUILD --- lib/new_version.dart | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/new_version.dart b/lib/new_version.dart index c628de9..99dccd6 100644 --- a/lib/new_version.dart +++ b/lib/new_version.dart @@ -29,8 +29,16 @@ class VersionStatus { /// Returns `true` if the store version of the application is greater than the local version. bool get canUpdate { - final local = localVersion.split('.').map(int.parse).toList(); - final store = storeVersion.split('.').map(int.parse).toList(); + // final local = localVersion.split('.').map(int.parse).toList(); + // final store = storeVersion.split('.').map(int.parse).toList(); + + //The version CAN look like this as well: 1.0.3+77. + String localBuildNumber = localVersion.split("+").length > 1 ? localVersion.split("+")[1] : "0"; + String storeBuildNumber = storeVersion.split("+").length > 1 ? storeVersion.split("+")[1] : "0"; + final local = localVersion.split('+')[0].split(".").map(int.parse).toList(); + local.add(int.parse(localBuildNumber)); + final store = storeVersion.split('+')[0].split(".").map(int.parse).toList(); + store.add(int.parse(storeBuildNumber)); // Each consecutive field in the version notation is less significant than the previous one, // therefore only one comparison needs to yield `true` for it to be determined that the store @@ -107,15 +115,15 @@ class NewVersion { } else if (Platform.isAndroid) { return _getAndroidStoreVersion(packageInfo); } else { - debugPrint( - 'The target platform "${Platform.operatingSystem}" is not yet supported by this package.'); + debugPrint('The target platform "${Platform.operatingSystem}" is not yet supported by this package.'); } } - /// This function attempts to clean local version strings so they match the MAJOR.MINOR.PATCH + /// This function attempts to clean local version strings so they match the MAJOR.MINOR.PATCH+BUILD /// versioning pattern, so they can be properly compared with the store version. - String _getCleanVersion(String version) => - RegExp(r'\d+\.\d+\.\d+').stringMatch(version) ?? '0.0.0'; + String _getCleanVersion(String version) { + return RegExp(r'\d+\.\d+\.\d+\+\d+').stringMatch(version) ?? '0.0.0+0'; + } /// iOS info is fetched by using the iTunes lookup API, which returns a /// JSON document. @@ -139,19 +147,16 @@ class NewVersion { } return VersionStatus._( localVersion: _getCleanVersion(packageInfo.version), - storeVersion: - _getCleanVersion(forceAppVersion ?? jsonObj['results'][0]['version']), + storeVersion: _getCleanVersion(forceAppVersion ?? jsonObj['results'][0]['version']), appStoreLink: jsonObj['results'][0]['trackViewUrl'], releaseNotes: jsonObj['results'][0]['releaseNotes'], ); } /// Android info is fetched by parsing the html of the app store page. - Future _getAndroidStoreVersion( - PackageInfo packageInfo) async { + Future _getAndroidStoreVersion(PackageInfo packageInfo) async { final id = androidId ?? packageInfo.packageName; - final uri = - Uri.https("play.google.com", "/store/apps/details", {"id": "$id"}); + final uri = Uri.https("play.google.com", "/store/apps/details", {"id": "$id"}); final response = await http.get(uri); if (response.statusCode != 200) { debugPrint('Can\'t find an app in the Play Store with the id: $id'); @@ -169,10 +174,7 @@ class NewVersion { final releaseNotesElement = sectionElements.firstWhereOrNull( (elm) => elm.querySelector('.wSaTQd')!.text == 'What\'s New', ); - final releaseNotes = releaseNotesElement - ?.querySelector('.PHBdkd') - ?.querySelector('.DWPxHb') - ?.text; + final releaseNotes = releaseNotesElement?.querySelector('.PHBdkd')?.querySelector('.DWPxHb')?.text; return VersionStatus._( localVersion: _getCleanVersion(packageInfo.version), @@ -200,8 +202,7 @@ class NewVersion { }) async { final dialogTitleWidget = Text(dialogTitle); final dialogTextWidget = Text( - dialogText ?? - 'You can now update this app from ${versionStatus.localVersion} to ${versionStatus.storeVersion}', + dialogText ?? 'You can now update this app from ${versionStatus.localVersion} to ${versionStatus.storeVersion}', ); final updateButtonTextWidget = Text(updateButtonText); @@ -226,8 +227,7 @@ class NewVersion { if (allowDismissal) { final dismissButtonTextWidget = Text(dismissButtonText); - dismissAction = dismissAction ?? - () => Navigator.of(context, rootNavigator: true).pop(); + dismissAction = dismissAction ?? () => Navigator.of(context, rootNavigator: true).pop(); actions.add( Platform.isAndroid ? TextButton( From f9a019bb5dedc796952118cfa64f9e1263ecd165 Mon Sep 17 00:00:00 2001 From: FredM7 Date: Mon, 28 Mar 2022 19:06:53 +0200 Subject: [PATCH 2/5] fix to include local verion build number --- lib/new_version.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/new_version.dart b/lib/new_version.dart index 99dccd6..eff347d 100644 --- a/lib/new_version.dart +++ b/lib/new_version.dart @@ -146,7 +146,7 @@ class NewVersion { return null; } return VersionStatus._( - localVersion: _getCleanVersion(packageInfo.version), + localVersion: _getCleanVersion("${packageInfo.version}${packageInfo.buildNumber.isNotEmpty ? "+${packageInfo.buildNumber}" : ""}"), storeVersion: _getCleanVersion(forceAppVersion ?? jsonObj['results'][0]['version']), appStoreLink: jsonObj['results'][0]['trackViewUrl'], releaseNotes: jsonObj['results'][0]['releaseNotes'], @@ -177,7 +177,7 @@ class NewVersion { final releaseNotes = releaseNotesElement?.querySelector('.PHBdkd')?.querySelector('.DWPxHb')?.text; return VersionStatus._( - localVersion: _getCleanVersion(packageInfo.version), + localVersion: _getCleanVersion("${packageInfo.version}${packageInfo.buildNumber.isNotEmpty ? "+${packageInfo.buildNumber}" : ""}"), storeVersion: _getCleanVersion(forceAppVersion ?? storeVersion), appStoreLink: uri.toString(), releaseNotes: releaseNotes, From a2a9bf9009eb5f0512b34cc8dadb164c2def873f Mon Sep 17 00:00:00 2001 From: Fred <12495374+FredM7@users.noreply.github.com> Date: Tue, 12 Apr 2022 15:51:36 +0200 Subject: [PATCH 3/5] Update lib/new_version.dart Co-authored-by: Jason Held --- lib/new_version.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_version.dart b/lib/new_version.dart index eff347d..c2acc43 100644 --- a/lib/new_version.dart +++ b/lib/new_version.dart @@ -122,7 +122,7 @@ class NewVersion { /// This function attempts to clean local version strings so they match the MAJOR.MINOR.PATCH+BUILD /// versioning pattern, so they can be properly compared with the store version. String _getCleanVersion(String version) { - return RegExp(r'\d+\.\d+\.\d+\+\d+').stringMatch(version) ?? '0.0.0+0'; + return RegExp(r'\d+\.\d+\.\d+(\+\d+)?').stringMatch(version) ?? '0.0.0+0'; } /// iOS info is fetched by using the iTunes lookup API, which returns a From cf3d5dd371bcdf944a5463c894ab6ebedebf5a40 Mon Sep 17 00:00:00 2001 From: Fred Date: Mon, 29 May 2023 11:35:49 +0200 Subject: [PATCH 4/5] use package_info_plus: ^4.0.1 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index bbe79c9..088e173 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: flutter: sdk: flutter - package_info_plus: ^1.0.0 + package_info_plus: ^4.0.1 http: ^0.13.1 html: ^0.15.0 url_launcher: ^6.0.2 From 9f0ab06c24e186bb88b08de67d0ef81acc8a4fac Mon Sep 17 00:00:00 2001 From: Fred Date: Mon, 29 May 2023 13:26:02 +0200 Subject: [PATCH 5/5] try package_info_plus: ^3.1.2 --- pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 088e173..41de805 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,8 @@ environment: dependencies: flutter: sdk: flutter - package_info_plus: ^4.0.1 + # package_info_plus: ^4.0.1 + package_info_plus: ^3.1.2 http: ^0.13.1 html: ^0.15.0 url_launcher: ^6.0.2