in_app_review
| Package | Kind | Provides the role | Needs | Choose with |
|---|---|---|---|---|
smf_in_app_review | infrastructure | Store reviews | Preferences, values in .env | -m in_app_review |
in_app_review asks the store of the platform for its own review dialog with in_app_review: StoreKit on iOS, and the In-App Review API of Google Play on Android. The code of the app never uses the package. It calls appReview.requestIfDue() of the store reviews role at a natural break, such as when the user has finished a task, and the role decides whether a review is due; see Store reviews and feedback.
The role counts the launches of the app in the preferences and reads the App Store ID of the app from .env, so the module brings shared_preferences and dart_define while they are the only providers of those roles. The role uses the router, the settings screen and the localization: in an app with guards of the routes, the app asks for no review in their flows, and in an app with a settings screen the row "Rate the app" opens the page of the app in its store.
What it adds to the app
| In the app | What it is |
|---|---|
in_app_review: ^2.0.12 in the dependencies | The package. In lib/, only the file below imports it. |
url_launcher: any and package_info_plus: any in the dependencies | url_launcher opens the page of the store, and package_info_plus reads the version of the app. The constraint any leaves their versions to the other modules of the app that take them. |
lib/core/review/in_app_review_service.dart | InAppReviewService, which implements ReviewService of the role, and createInAppReviewService(), which creates it with the app. |
| The section "in_app_review" of the README | What shows the dialog, how to see it on Android before the app is published, and what Google Play collects through it. |
Whichever module provides it, the store reviews role adds these files:
| File | What it holds |
|---|---|
lib/core/review/app_review.dart | appReview, through which the code of the app asks for a review and opens the store page, ReviewPolicy with the numbers of when a review is due, googlePlayId, the application id of the app in Google Play, restoreReview, the restorer of the preferences, and initReview(). |
lib/core/review/review_service.dart | ReviewService, the interface that this module implements. |
lib/core/review/review_setting.dart, in an app with a settings screen | ReviewSetting, the row "Rate the app", and reviewSettingShows(), which hides it where the app has no store page. |
The role also gives .env the key REVIEW_APP_STORE_ID, the App Store ID of the app, and in an app with guards of the routes gives the router noteScreenForReview, a listener of the screen that the user sees. bootstrap() awaits initReview() in its last phase, once the services of the app are ready, which creates the service and counts the launch. This is bootstrap() of an app with this module, shared_preferences and dart_define:
Future<void> bootstrap() async {
checkEnvValues(debugPrint);
await initPreferences();
await initReview();
}
The module needs nothing in the native projects.
In the guide for coding agents of the app, the role describes appReview under "Store reviews". The module adds which file is on in_app_review, why the app never calls openStoreListing() of the package, where the app asks for the dialog and how to see it on Android, and what Google Play collects through it.
How the service works
| What the service does | Why |
|---|---|
requestReview() asks for the dialog with InAppReview.instance.requestReview(), and lets an error of the platform that refuses the request through. | The role counts a request only once the store took it. An error counts as no dialog, so a later call asks again. |
isAvailable() asks the package whether the store of the device can show the dialog, and answers false when the package fails to tell. | On a device without the review service of Google Play, the app does not ask. |
openStorePage() opens exactly the page that appReview gives it, outside the app, with launchUrl of url_launcher, and returns false when no app opens it. | openStoreListing() of in_app_review opens, on Android, the page of the id of the build that runs, such as that of the flavor dev, which has no page in Google Play. appReview gives the page of the flavor for a release. |
appVersion() is the version name of the app from PackageInfo.fromPlatform(), without the build number. | The app asks at most once a version. |
See the dialog on Android
Google Play shows the dialog only in an app that it installed. To see it before the app is published, as the README of the app tells (Test in-app reviews of Google):
- Upload a build of the flavor
prodto the internal test track in Play Console. - Add a Gmail account to the testers of that track. It is the primary account of the Play Store on the device: an account of Google Workspace does not work.
- Install the app once from the internal test track with that account. From then on, local builds of the flavor
prodmay show the dialog on that device: uninstall the copy from Google Play first, since a local build has another signature. Google Play does not limit how often it shows the dialog to an app from the internal test track. - Never send the review of a test, or delete it in the Play Store: Google Play shows no dialog to an account that has reviewed the app.
An app from internal app sharing shows the dialog too, but its review cannot be sent. Elsewhere on Android:
- On a device without the review service of Google Play, such as an emulator without the Play Store, the store cannot take the request, the app records nothing, and the next call of
appReview.requestIfDue()asks again. - On a device with the Play Store, for a build that Google Play did not install, such as a local build of the flavor
dev, the request completes and shows nothing. The app counts it as a request, so it does not ask again in that version of the app.
Through the dialog, Google Play collects the rating and the text of the review, which become a public review on Google Play, or which only you see for an app on a closed test track: see the section "Data Safety" of the In-App Review API. The privacy manifest of in_app_review on iOS declares no data that it collects. Both stores require a link to a privacy policy in the listing of the app and inside the app.
What the module does not do
- It asks for no review on its own. Only a call of
appReview.requestIfDue()in the code of the app asks. - It shows nothing around the dialog: no question of its own, no text and no screen.
- It never tells the app whether the dialog showed or what the user did, since the store tells nobody.
- It never asks for the dialog from a button. The row "Rate the app" opens the page of the store.
- It never opens a page through
openStoreListing()of in_app_review.
Finish the setup
On Android, the app has its Google Play page right after smf create. On iOS, it has an App Store page only once .env has the App Store ID of the app. The README lists that step in its section "Finish the setup":
| Step | What you do |
|---|---|
review.app_store_id | Copy the App Store ID of the app, its Apple ID in App Store Connect, into REVIEW_APP_STORE_ID in .env. |
Until then, appReview.hasStorePage is false on iOS, the row "Rate the app" does not show there, and a debug build on iOS prints which key to fill in. The dialog itself needs no ID.
In tests
in_app_review has no mocks for tests. A test in which the service of the module asks the platform, such as through appReview.requestIfDue() when a review is due, answers the method channel of the package, dev.britannio.in_app_review, itself, with setMockMethodCallHandler of TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger, and gives package_info_plus values with PackageInfo.setMockInitialValues. A test of a screen needs none of this: it starts a controller with a service of its own; see Store reviews and feedback.
Whichever module provides the role, no review is due before the third launch or before three days have passed, the app asks once a version and not again within 14 days, and nothing shows around the dialog. SMF's CI checks this in running apps with the role. For this module, it checks over a stand-in for the platform side of in_app_review, a device whose store can show the dialog and on which a request completes at once: what each call of the service sends, that openStorePage() gives url_launcher exactly the page on Android and on iOS, that the version has no build number, and that a request that the platform refuses saves nothing and reaches no handler of the errors of the app, so the next call asks again. See Contributing.
Choosing it
smf create asks "Store reviews: which module provides it?" and offers this module first, so Enter takes it. The answer may be none. To choose it without the question:
smf create my_app -m in_app_review
smf create then adds shared_preferences and dart_define, the only providers of the preferences and of the values in .env, which the role requires. update_required requires the store reviews role for its button "Update", so with it smf create adds this module without a question while it is the only one that provides the role.