74

How can I open a specific URL of the PlayStore/AppStore with flutter on Android and IOS, depending on which smartphone it is executed? I mean I want to open the application and not a browser or something like this.

In this thread I found some native way for android but how can I do this with flutter?

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

If there is currently no way to do this, it would be a nice feature to implement for the plugin url_launcher.

1

8 Answers 8

81

You can use url_luncher and open the url based on the platform like this:

import 'package:url_launcher/url_launcher.dart';

if (Platform.isAndroid || Platform.isIOS) {
  final appId = Platform.isAndroid ? 'YOUR_ANDROID_PACKAGE_ID' : 'YOUR_IOS_APP_ID';
  final url = Uri.parse(
    Platform.isAndroid
        ? "market://details?id=$appId"
        : "https://apps.apple.com/app/id$appId",
  );
  launchUrl(
    url,
    mode: LaunchMode.externalApplication,
  );
}

Note

  • You can get your iOS app id from http://itunes.apple.com/lookup?bundleId=YOUR_BUNDLE_ID then look for trackId
  • This wont work on iOS simulators as they don't have an app store
  • Setting the mode to LaunchMode.externalApplication will prevent the safari flash for a second
8
  • please make an example for YOUR_BUNDLE_ID for 1 app on apple store . Commented Jun 28, 2022 at 11:43
  • YOUR_BUNDLE_ID = Bundle Identifier thats mean packange name ??? or how ??? { "resultCount":0, "results": [] } Commented Jun 28, 2022 at 11:49
  • Here is an example with the apple pages app itunes.apple.com/lookup?bundleId=com.apple.Pages
    – Iain Smith
    Commented Jun 28, 2022 at 13:50
  • 1
    You will have set a bundle id for your iOS app so use that, it will be in your signing and capabilities section something like com.companyname.appname
    – Iain Smith
    Commented Jun 28, 2022 at 13:51
  • But its return file txt right ? Why not a json ? So in flutter we need to handle the download file and casting or read the inside file content right ? Commented Jun 28, 2022 at 19:08
54

You can use this Library,

Basically, To use this plugin, add launch_review as a dependency in your pubspec.yaml file.

launch_review: ^1.0.1

To use :

 import 'package:launch_review/launch_review.dart'; 

Then invoke the static launch method of LaunchReview anywhere in your Dart code. If no arguments are provided, it will consider the current package.

LaunchReview.launch();

To open the App Store page for any other applications, you can pass the app Id.

LaunchReview.launch(androidAppId: <package name>,
                iOSAppId: <ios app id>);
6
  • Great thank you. :) I will try to implement it later . Commented Jun 11, 2018 at 12:38
  • Not using flutter for more than 10 months. Please consider adding a issue in Github repo of library. Maintainers may reply to you there itself.
    – Naroju
    Commented Feb 17, 2019 at 10:51
  • 3
    now it has writeReview option, so LaunchReview.launch(writeReview: false); Commented Mar 3, 2020 at 0:09
  • 1
    For future users, for iOS this no longer works unless you specify the iosAppId explicitly. Commented Feb 16, 2022 at 11:28
  • make sure you pass the package name to whatever plugin you use, I was passing an empty string.
    – Ray Rojas
    Commented Mar 20, 2023 at 18:37
11

You can do something similar in flutter:

import 'package:url_launcher/url_launcher.dart';

try {
  launch("market://details?id=" + appPackageName);
} on PlatformException catch(e) {
    launch("https://play.google.com/store/apps/details?id=" + appPackageName);        
} finally {
  launch("https://play.google.com/store/apps/details?id=" + appPackageName);        
}

The exception/catch does not seem to work for some reason so adding 'finally' did the trick, finally :)

8
  • 2
    You cannot catch an exception that occurs in a function/method returning Future unless you put await when you call it.
    – kaboc
    Commented May 27, 2020 at 5:29
  • ahhh I see, but how come the 'finally' part gets executed?
    – K Vij
    Commented May 28, 2020 at 1:24
  • 3
    The finally block is executed regardless of whether an exception occurred of not. I suspect that your code tries to open the store twice.
    – kaboc
    Commented May 28, 2020 at 10:19
  • hmm... i don't see that behavior... I'll test again.
    – K Vij
    Commented May 28, 2020 at 18:21
  • On flutter web, on Chrome Mobile the first method does not work, hence it opens the play store on the ugly web site.
    – MappaM
    Commented Mar 22, 2021 at 11:57
11

This is like the most popular answer to this question, but without the need of saying the Android package. In addition, this solution doesn't show a toast on Android saying "Please Rate Application".

It depends on open_store and package_info_plus.

const appStoreId = "1234567890"; // Your app's App Store ID
final packageName = (await PackageInfo.fromPlatform()).packageName;

OpenStore.instance.open(
  androidAppBundleId: packageName,
  appStoreId: appStoreId,
);
9

You can use the url_launcher package for opening the appstore/playstore as follows :

      _launchURL(String url) async {
         if (await canLaunch(url)) {
             await launch(url);
         } 
         else {
             throw 'Could not launch $url';
         }
       }
1
4

You can use this plug in. here

Super simple. To use this pulg in, just write the package name (app id) on your dart code like this.

OpenAppstore.launch(androidAppId: "com.facebook.katana&hl=ko", iOSAppId: "284882215")
2
  • How do I find my iOSAppId? Struggling to locate this Commented Jun 16, 2021 at 21:38
  • It doesn't support Sound Null Safety :·( In addition, Android package name could be automatically read from the app build itself... Commented Mar 17, 2022 at 11:56
0

You can also try store_launcher

Example

StoreLauncher.openWithStore(appId);
1
  • It doesn't support Sound Null Safety :·( In addition, Android package name could be automatically read from the app build itself... Commented Mar 17, 2022 at 11:54
0

Function to open the App Store or Play Store URL in yo flutter app

Future<void> _openStore() async {
String packageName = 'put your_package_name';
String appStoreUrl = 'https://apps.apple.com/app/$packageName';
String playStoreUrl = 'https://play.google.com/store/apps/details?id=$packageName';

if (await canLaunch(appStoreUrl) && !Platform.isAndroid) {
  await launch(appStoreUrl);
} else if (await canLaunch(playStoreUrl) && Platform.isAndroid) {
  await launch(playStoreUrl);
} else {
  throw 'Could not launch store';
}

}

Not the answer you're looking for? Browse other questions tagged or ask your own question.