64

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

7 Answers 7

58

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
7
  • please make an example for YOUR_BUNDLE_ID for 1 app on apple store . Jun 28, 2022 at 11:43
  • YOUR_BUNDLE_ID = Bundle Identifier thats mean packange name ??? or how ??? { "resultCount":0, "results": [] } 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
    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
    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 ? Jun 28, 2022 at 19:08
53

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>);
5
  • Great thank you. :) I will try to implement it later . 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
    Feb 17, 2019 at 10:51
  • 3
    now it has writeReview option, so LaunchReview.launch(writeReview: false); Mar 3, 2020 at 0:09
  • 1
    For future users, for iOS this no longer works unless you specify the iosAppId explicitly. 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
    Mar 20 at 18:37
10

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 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
    May 27, 2020 at 5:29
  • ahhh I see, but how come the 'finally' part gets executed?
    – K Vij
    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
    May 28, 2020 at 10:19
  • hmm... i don't see that behavior... I'll test again.
    – K Vij
    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
    Mar 22, 2021 at 11:57
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 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... 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... Mar 17, 2022 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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