diff --git a/example/lib/main.dart b/example/lib/main.dart index d6b0f2a..804adf9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -39,11 +39,8 @@ class _MyHomePageState extends State { } void _verifyVersion() async { - PackageInfo? packageInfo = await PackageInfo.fromPlatform(); await AppVersionUpdate.checkForUpdates( - appleId: '284882215', - playStoreId: 'com.facebook.katana', - country: 'br') + appleId: '1459706595', playStoreId: 'com.byebnk.app', country: 'br') .then((data) async { print(data); if (data.canUpdate!) { diff --git a/example/pubspec.lock b/example/pubspec.lock index 0ada6c4..f7b0adc 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -4,10 +4,10 @@ packages: app_version_update: dependency: "direct main" description: - name: app_version_update - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.3" + path: ".." + relative: true + source: path + version: "3.0.0" async: dependency: transitive description: @@ -136,7 +136,7 @@ packages: source: hosted version: "1.8.0" package_info_plus: - dependency: "direct main" + dependency: transitive description: name: package_info_plus url: "https://pub.dartlang.org" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index e25cb61..62dd13f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 1.0.0 # nothing update # version: 1000.0.0+1 @@ -31,9 +31,8 @@ environment: dependencies: flutter: sdk: flutter - package_info_plus: app_version_update: - # path: ../ + path: ../ # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/lib/app_version_update.dart b/lib/app_version_update.dart index 653410b..98e130d 100644 --- a/lib/app_version_update.dart +++ b/lib/app_version_update.dart @@ -41,17 +41,20 @@ class AppVersionUpdate { Uri.https(playStoreAuthority, playStoreUndecodedPath, parameters); final response = await http.get(uri, headers: headers).catchError((e) => throw e); - AppVersionResult appVersionResult = AppVersionResult( - canUpdate: convertVersion( - version: packageInfo.version, - versionStore: RegExp(r',\[\[\["([0-9,\.]*)"]],') - .firstMatch(response.body)! - .group(1)!), - storeUrl: uri.toString(), - storeVersion: RegExp(r',\[\[\["([0-9,\.]*)"]],') - .firstMatch(response.body)! - .group(1), - platform: TargetPlatform.android); + AppVersionResult? appVersionResult; + final versionMatch = + RegExp(r',\[\[\["([0-9,\.]*)"]],').firstMatch(response.body); + if (versionMatch != null) { + appVersionResult = AppVersionResult( + canUpdate: convertVersion( + version: packageInfo.version, + versionStore: versionMatch.group(1)!), + storeUrl: uri.toString(), + storeVersion: versionMatch.group(1), + platform: TargetPlatform.android); + } else { + throw "Could not find version information in Play Store response."; + } if (response.statusCode != 200) { throw " Aplication not found in Play Store, verify your app id. "; }