Skip to content

Commit 6540968

Browse files
Added Google playstore as default fallback marketplace for android.
1 parent 1ee3acb commit 6540968

File tree

6 files changed

+45
-25
lines changed

6 files changed

+45
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes will be documented in this file.
44

5+
## [1.0.8] - 2023-03-01
6+
* Add Google playstore as default fallback marketplace for android.
7+
58
## [1.0.7] - 2023-02-27
69
* Add support for Amazon, Huawei and other android marketplaces.
710

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ class MyApp extends StatelessWidget {
171171
}
172172
```
173173

174+
- preferredAndroidMarket: PreferredAndroidMarket.amazon // or PreferredAndroidMarket.huawei or PreferredAndroidMarket.other If not provided default is Google playstore. If SDK fails to open preferred market place in case marketplace is not available then default Google playstore will be open.
175+
174176
If you want to redirect user to some other android market place you can use the following example:
177+
```
178+
preferredAndroidMarket: PreferredAndroidMarket.other
179+
otherAndroidMarketUrl: 'https://someotherandroidmarket.com/app/id'// Required if preferredAndroidMarket is Other.
180+
```
175181
```dart
176182
import 'package:flutter/material.dart';
177183
import 'package:app_upgrade_flutter_sdk/app_upgrade_flutter_sdk.dart';

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class _MyHomePageState extends State<MyHomePage> {
5959
platform: 'android',
6060
environment: 'production',
6161
appLanguage: 'es',
62-
// preferredAndroidMarket: PreferredAndroidMarket.amazon, // or PrefferedAndroidMarket.huawei or PrefferedAndroidMarket.other If not provided default android marketplace is Google playstore. Optional
62+
// preferredAndroidMarket: PreferredAndroidMarket.huawei, // or PrefferedAndroidMarket.huawei or PrefferedAndroidMarket.other If not provided default android marketplace is Google playstore. Optional
6363
// otherAndroidMarketUrl: 'https://otherandroidmarketplaceurl.com/app/id', // Required only if PreferredAndroidMarket is other.
6464
);
6565

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
path: ".."
88
relative: true
99
source: path
10-
version: "1.0.7"
10+
version: "1.0.8"
1111
async:
1212
dependency: transitive
1313
description:

lib/src/app_upgrade.dart

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ class AppUpgrade {
6969
// show force upgrade dialog
7070
Future.delayed(const Duration(milliseconds: 0), () {
7171
_showDialog(
72-
context: context,
73-
title: dialogConfig.title ?? defaultDialogTitle,
74-
message: version.message,
75-
canDismissDialog: false,
76-
appInfo: appInfo
77-
);
72+
context: context,
73+
title: dialogConfig.title ?? defaultDialogTitle,
74+
message: version.message,
75+
canDismissDialog: false,
76+
appInfo: appInfo);
7877
});
7978
} else {
8079
if (debug) {
@@ -84,12 +83,11 @@ class AppUpgrade {
8483
// show upgrade dialog
8584
Future.delayed(const Duration(milliseconds: 0), () {
8685
_showDialog(
87-
context: context,
88-
title: dialogConfig.title ?? defaultDialogTitle,
89-
message: version.message,
90-
canDismissDialog: true,
91-
appInfo: appInfo
92-
);
86+
context: context,
87+
title: dialogConfig.title ?? defaultDialogTitle,
88+
message: version.message,
89+
canDismissDialog: true,
90+
appInfo: appInfo);
9391
});
9492
}
9593
} else {
@@ -146,7 +144,8 @@ class AppUpgrade {
146144
actions: <Widget>[
147145
if (canDismissDialog == true)
148146
TextButton(
149-
child: Text(dialogConfig.laterButtonTitle ?? defaultLaterButtonTitle),
147+
child: Text(
148+
dialogConfig.laterButtonTitle ?? defaultLaterButtonTitle),
150149
onPressed: () => onUserLater(context)),
151150
TextButton(
152151
child: Text(
@@ -210,23 +209,35 @@ class AppUpgrade {
210209
if (Platform.isAndroid) {
211210
if (appInfo.preferredAndroidMarket == PreferredAndroidMarket.google) {
212211
url = "https://play.google.com/store/apps/details?id=$appId";
213-
} else if (appInfo.preferredAndroidMarket == PreferredAndroidMarket.huawei) {
212+
} else if (appInfo.preferredAndroidMarket ==
213+
PreferredAndroidMarket.huawei) {
214214
url = "appmarket://details?id=$appId";
215-
} else if (appInfo.preferredAndroidMarket == PreferredAndroidMarket.amazon) {
215+
} else if (appInfo.preferredAndroidMarket ==
216+
PreferredAndroidMarket.amazon) {
216217
url = "https://www.amazon.com/gp/mas/dl/android?p=$appId";
217-
} else if (appInfo.preferredAndroidMarket == PreferredAndroidMarket.other && appInfo.otherAndroidMarketUrl != null) {
218+
} else if (appInfo.preferredAndroidMarket ==
219+
PreferredAndroidMarket.other &&
220+
appInfo.otherAndroidMarketUrl != null) {
218221
url = appInfo.otherAndroidMarketUrl!;
219222
} else {
220223
url = "https://play.google.com/store/apps/details?id=$appId";
221224
}
225+
226+
try {
227+
await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
228+
} catch (e) {
229+
if (debug) {
230+
print(
231+
'App Upgrade Error: Could not open the preferred android market. Defaulting to Google Playstore.');
232+
}
233+
await launchUrl(
234+
Uri.parse('https://play.google.com/store/apps/details?id=$appId'),
235+
mode: LaunchMode.externalApplication);
236+
}
222237
} else if (Platform.isIOS) {
223-
url = "https://apps.apple.com/app/id/$appId";
238+
url = "https://apps.apple.com/app/id/$appId";
239+
await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
224240
}
225-
226-
launchUrl(
227-
Uri.parse(url),
228-
mode: LaunchMode.externalApplication,
229-
);
230241
} catch (e) {
231242
if (debug) {
232243
print('App Upgrade: launch to app store failed: $e');

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: app_upgrade_flutter_sdk
22
description: The official Flutter SDK for App Upgrade. The SDK integrates with the App Upgrade version check API.
3-
version: 1.0.7
3+
version: 1.0.8
44
homepage: https://github.com/appupgrade-dev/app_upgrade_flutter_sdk
55

66
environment:

0 commit comments

Comments
 (0)