### Example: Launch Windows Store Link Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Example of using the private _launchUrl method to open a Windows Store link. ```dart await _launchUrl('ms-windows-store://review/?ProductId=App123'); ``` -------------------------------- ### Use InAppReviewPlatform Instance Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReviewPlatform.md Example of how to get the platform instance and check if the review feature is available. ```dart final platform = InAppReviewPlatform.instance; final available = await platform.isAvailable(); ``` -------------------------------- ### Example: Open Windows Store Listing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Example of how to open the Microsoft Store listing for a specific app using its ID. ```dart await impl.openStoreListing(microsoftStoreId: 'MyAppId'); ``` -------------------------------- ### MethodChannel invocation example (Kotlin) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/types.md Example of how to create a MethodChannel and invoke a method on it in native Android plugin code. ```kotlin val channel = MethodChannel(binaryMessenger, "dev.britannio.in_app_review") channel.invokeMethod("methodName", arguments) ``` -------------------------------- ### Example: Open iOS Store Listing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Example of how to open the Apple App Store listing for a specific app using its ID. ```dart final impl = MethodChannelInAppReview(); await impl.openStoreListing(appStoreId: '1234567890'); ``` -------------------------------- ### Open Store Listing Example Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReviewPlatform.md Demonstrates how to open the store listing for the app to allow users to write reviews. This method requires platform-specific IDs for certain platforms. ```dart final platform = InAppReviewPlatform.instance; try { await platform.openStoreListing( appStoreId: '1234567890', ); } catch (e) { print('Failed to open store listing: $e'); } ``` -------------------------------- ### openStoreListing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/AndroidInAppReviewPlugin.md Opens the Google Play Store listing for the app. It checks for context and activity availability, constructs a deep link to the Play Store, and starts the activity to open it. Returns success or an error if an exception occurs. ```APIDOC ## openStoreListing ### Description Opens the Google Play Store listing for the app. This method ensures that the necessary Android context and activity are available before attempting to open the Play Store. ### Method Implicitly called via plugin channel. ### Endpoint N/A (Plugin method) ### Parameters None directly exposed to the caller. Internal parameters are handled by the plugin. ### Request Example N/A (Plugin method) ### Response #### Success Response - `null`: Indicates the Play Store listing was successfully opened. #### Error Response - `error` (string): A general error code. - `message` (string): "An error occurred while opening the play store" - `details` (any): `null` ### Behavior 1. Checks for context and activity availability. 2. Retrieves the application's package name. 3. Constructs a deep link Intent to the Play Store using the app's package name. 4. Starts the activity to open the Play Store. 5. Returns success (null) upon successful execution. 6. Catches any exceptions and returns an error response. ``` -------------------------------- ### Mock InAppReviewPlatform Instance for Testing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReviewPlatform.md Example of how to set a mock implementation of InAppReviewPlatform for testing purposes. ```dart InAppReviewPlatform.instance = MockInAppReviewPlatform(); ``` -------------------------------- ### isAvailable method check for web Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/types.md Example of how the isAvailable method in the plugin checks for the web platform and returns false. ```dart @override Future isAvailable() async { if (kIsWeb) return false; // ... delegate to platform } ``` -------------------------------- ### Open Play Store Listing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/AndroidInAppReviewPlugin.md Opens the Google Play Store listing for the app. It checks for context and activity availability before constructing and starting an intent to the Play Store. Returns success or an error if an exception occurs. ```kotlin private fun openStoreListing(result: Result) { Log.i(TAG, "openStoreListing: called") if (noContextOrActivity(result)) return try { val packageName = context!!.packageName val intent = Intent(Intent.ACTION_VIEW) .setData("https://play.google.com/store/apps/details?id=$packageName".toUri()) activity!!.startActivity(intent) result.success(null) } catch (e: Exception) { Log.e(TAG, "openStoreListing: error", e) result.error( "error", "An error occurred while opening the play store", null ) } } ``` -------------------------------- ### Get InAppReviewPlatform Instance Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReviewPlatform.md Retrieves the current platform implementation instance. Defaults to MethodChannelInAppReview(). ```dart static InAppReviewPlatform get instance => _instance; ``` -------------------------------- ### Handle General Android Play Store Opening Error Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/errors.md Catch PlatformException with code 'error' when an issue occurs while attempting to open the Google Play Store listing on Android. This can be due to various reasons, including the Play Store not being installed or responsive. ```dart try { await inAppReview.openStoreListing(); } on PlatformException catch (e) { if (e.code == "error") { print('Failed to open store: ${e.message}'); } } ``` -------------------------------- ### Implement Custom Dart Logging for In-App Review Errors Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md This example shows how to implement custom logging in Dart for in-app review errors using the 'dart:developer' library. This is useful when specific platform exception handling is not required or as a fallback. ```dart import 'dart:developer' as developer; try { await inAppReview.requestReview(); } catch (e) { developer.log('InAppReview error: $e'); } ``` -------------------------------- ### Example Availability enum Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/types.md An example Dart enum for tracking the availability state, often associated with the result of an isAvailable() method. ```dart enum Availability { loading, available, unavailable } ``` -------------------------------- ### Version Adaptation Strategy with #available Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/macOSInAppReviewPlugin.md Demonstrates how to use Swift's #available attribute for compile-time version checking to adapt code for different macOS versions. ```swift if #available(OSX 13.0, *) { // macOS 13+ code } else if #available(OSX 10.14, *) { // macOS 10.14-12 code } else { // Unsupported } ``` -------------------------------- ### Platform Implementation Pattern Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReviewPlatform.md Illustrates the recommended pattern for platform implementations of InAppReviewPlatform. Implementations should extend the base class and override the required methods. ```dart class MethodChannelInAppReview extends InAppReviewPlatform { @override Future isAvailable() async { // Implementation } @override Future requestReview() async { // Implementation } @override Future openStoreListing({ String? appStoreId, String? microsoftStoreId, }) async { // Implementation } } ``` -------------------------------- ### Usage Pattern for noContextOrActivity Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/AndroidInAppReviewPlugin.md Demonstrates the recommended usage pattern for the `noContextOrActivity` helper method to ensure context and activity are available before proceeding. ```kotlin if (noContextOrActivity(result)) return // Safe to use context!! and activity!! ``` -------------------------------- ### FlutterResult success callback (Kotlin) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/types.md Example of how to use the success method of the FlutterResult interface in native Android plugin code. ```kotlin interface Result { fun success(result: Any?) fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) fun notImplemented() } ``` -------------------------------- ### Get Singleton Instance of InAppReview Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReview.md Access the singleton instance of InAppReview to use its functionalities. This is the primary way to interact with the review API. ```dart static final InAppReview instance = InAppReview._(); ``` ```dart final inAppReview = InAppReview.instance; ``` -------------------------------- ### InAppReview Plugin Entry Point and Primary Methods Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/README.md This snippet shows how to access the InAppReview plugin instance and use its primary methods: isAvailable(), requestReview(), and openStoreListing(). These methods are the main interface for interacting with the in-app review functionality across supported platforms. ```APIDOC ## Entry Point ### Description Access the singleton instance of the InAppReview plugin. ### Code ```dart import 'package:in_app_review/in_app_review.dart'; final inAppReview = InAppReview.instance; ``` ## Primary Methods ### Description These are the core methods provided by the InAppReview plugin to interact with the review and store listing functionalities. ### Methods #### `isAvailable()` - **Description**: Checks if the in-app review functionality is available on the current device and platform. - **Return**: `Future` - Returns `true` if available, `false` otherwise. - **Platforms**: Android, iOS, macOS #### `requestReview()` - **Description**: Prompts the user to review the application. This is subject to platform-specific review quotas and may not be shown every time. - **Return**: `Future` - **Platforms**: Android, iOS, macOS #### `openStoreListing()` - **Description**: Opens the application's store listing page in the respective app store. This action is not subject to review quotas. - **Return**: `Future` - **Platforms**: Android, iOS, macOS, Windows ``` -------------------------------- ### Basic In App Review Usage Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/README.md Demonstrates how to check for review availability and request a review. Opens the store listing if the review is not available. ```dart final inAppReview = InAppReview.instance; // Check availability if (await inAppReview.isAvailable()) { // Request review (quota-limited) await inAppReview.requestReview(); } // Open store (no quota restriction) await inAppReview.openStoreListing( appStoreId: '1234567890', // iOS/macOS microsoftStoreId: 'MyAppId', // Windows ); ``` -------------------------------- ### Main Plugin pubspec.yaml Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md The pubspec.yaml file for the main in_app_review plugin. It lists dependencies and platform configurations. ```yaml name: in_app_review description: Flutter plugin for showing the In-App Review/System Rating pop up on Android, iOS and MacOS. version: 2.0.12 homepage: https://github.com/britannio/in_app_review/tree/master/in_app_review repository: https://github.com/britannio/in_app_review issue_tracker: https://github.com/britannio/in_app_review/issues environment: sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: flutter: sdk: flutter in_app_review_platform_interface: ^2.0.5 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^5.0.0 mockito: ^5.0.0 plugin_platform_interface: ^2.0.2 flutter: plugin: platforms: android: package: dev.britannio.in_app_review pluginClass: InAppReviewPlugin ios: pluginClass: InAppReviewPlugin macos: pluginClass: InAppReviewPlugin ``` -------------------------------- ### Open Store Listing for Windows Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReview.md Opens the app's store listing on Windows. Requires the Microsoft Store product ID. Use this when in-app review is not available or as a fallback. ```dart await inAppReview.openStoreListing( microsoftStoreId: 'YourAppId', ); ``` -------------------------------- ### Platform-Specific Store Listing Parameters Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/README.md Illustrates how to provide platform-specific IDs when opening the store listing. Android requires no parameters, while iOS/macOS and Windows require specific IDs. ```dart // iOS/macOS: appStoreId required await inAppReview.openStoreListing(appStoreId: '1234567890'); // Android: no parameters needed await inAppReview.openStoreListing(); // Windows: microsoftStoreId required await inAppReview.openStoreListing(microsoftStoreId: 'MyAppId'); // Both: provide both for universal fallback await inAppReview.openStoreListing( appStoreId: '1234567890', microsoftStoreId: 'MyAppId', ); ``` -------------------------------- ### openStoreListing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Opens the store listing for the app on the respective platform. It handles platform-specific logic for iOS, macOS, Android, and Windows. ```APIDOC ## openStoreListing ### Description Opens the store listing for the app on the respective platform. It handles platform-specific logic for iOS, macOS, Android, and Windows. ### Method Signature `Future openStoreListing({ String? appStoreId, String? microsoftStoreId })` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Platform-Specific Behavior **iOS and macOS:** - Requires `appStoreId` (String). - Validates `appStoreId` is not null. - Passes `appStoreId` to the native method channel. **Android:** - Invokes the native method channel with no arguments. **Windows:** - Requires `microsoftStoreId` (String). - Validates `microsoftStoreId` is not null. - Constructs and launches a deep link URL: `ms-windows-store://review/?ProductId={microsoftStoreId}`. ### Returns `Future` that completes when the store listing is opened. ### Throws - `ArgumentError` if a required platform-specific ID is null. - `UnsupportedError` if the platform is not supported. - Platform exceptions from native code. ### Example (iOS) ```dart final impl = MethodChannelInAppReview(); await impl.openStoreListing(appStoreId: '1234567890'); ``` ### Example (Windows) ```dart await impl.openStoreListing(microsoftStoreId: 'MyAppId'); ``` ``` -------------------------------- ### Open App Store Listing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/types.md Asynchronously opens the app's listing page in the respective app store. This operation has no return value and is used for its side effect. ```dart await inAppReview.openStoreListing(); ``` -------------------------------- ### openStoreListing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReview.md Opens the store listing for the app, allowing users to leave a review without quota restrictions. This method is platform-aware and requires specific store IDs for certain operating systems. ```APIDOC ## openStoreListing ### Description Opens the store listing for the app. This allows users to access the full store page and leave a review without quota restrictions. ### Method Signature `Future openStoreListing({ String? appStoreId, String? microsoftStoreId })` ### Parameters #### Path Parameters - **appStoreId** (`String?`) - Conditional - null - Apple App Store ID (required for iOS and macOS). Found in App Store Connect under General > App Information > Apple ID. - **microsoftStoreId** (`String?`) - Conditional - null - Microsoft Store product ID (required for Windows). Omit for other platforms. ### Platform-Specific Behavior: - **Android:** Opens Google Play Store app to the app's listing page via Intent - **iOS:** Opens App Store to app's review screen at URL `https://apps.apple.com/app/id{appStoreId}?action=write-review` - **macOS:** Opens Mac App Store to app's review screen at URL `macappstore://apps.apple.com/app/id{appStoreId}?action=write-review` - **Windows:** Opens Microsoft Store via deep link `ms-windows-store://review/?ProductId={microsoftStoreId}` - **Web:** Not supported ### Parameter Validation: - Throws `ArgumentError` if `appStoreId` is null on iOS/macOS - Throws `ArgumentError` if `microsoftStoreId` is null on Windows - Android does not require store ID parameters ### Error Handling: - iOS/macOS: Returns error with code `"no-store-id"` if store ID missing - iOS/macOS: Returns error with code `"url-construct-fail"` if URL construction fails - macOS: Returns error with code `"url_construct_fail"` if URL construction fails - Android: Returns error with code `"error"` with message if Intent fails - Windows: Handled by `url_launcher` package ### Returns A `Future` that completes when store is opened. ### Example (iOS/macOS): ```dart import 'package:in_app_review/in_app_review.dart'; final inAppReview = InAppReview.instance; await inAppReview.openStoreListing( appStoreId: '1234567890', // Your App Store ID ); ``` ### Example (Android): ```dart // appStoreId is not required on Android await inAppReview.openStoreListing(); ``` ### Example (Windows): ```dart await inAppReview.openStoreListing( microsoftStoreId: 'YourAppId', ); ``` ### Example (Fallback from unavailable requestReview): ```dart if (await inAppReview.isAvailable()) { await inAppReview.requestReview(); } else { // Fallback to store listing for devices without in-app review await inAppReview.openStoreListing( appStoreId: '1234567890', microsoftStoreId: 'YourAppId', ); } ``` ``` -------------------------------- ### openStoreListing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/iOSInAppReviewPlugin.md Opens the App Store to the review page for the specified app ID. Requires a valid store ID. Returns null on success or a FlutterError on failure. ```APIDOC ## openStoreListing ### Description Opens the App Store to the review page for the specified app ID. Requires a valid store ID. Returns null on success or a FlutterError on failure. ### Method Channel `openStoreListing` ### Arguments - **appStoreId** (String) - Required - The Apple App Store ID for the application. ### Return `null` on success, `FlutterError` on failure. ### Errors - Code: `"no-store-id"` (appStoreId missing) - Message: `"Your store id must be passed as the method channel's argument"` - Code: `"url-construct-fail"` (URL construction failed) - Message: `"Failed to construct url"` ``` -------------------------------- ### openStoreListing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/macOSInAppReviewPlugin.md Opens the Mac App Store page for the application, allowing users to view the store listing or write a review. Requires the application's store ID. ```APIDOC ## openStoreListing ### Description Opens the Mac App Store listing for the application, with a specific URL action to prompt for a review. ### Method Inline implementation within `handle(_:result:)`. ### Parameters - **storeId** (String) - The unique Apple App Store ID for the application. ### Endpoint Constructs a URL of the format: `"macappstore://apps.apple.com/app/id" + storeId + "?action=write-review"` ### Action Uses `NSWorkspace.shared.open()` to open the constructed URL in the Mac App Store. ### Returns - `result(nil)` on successful opening of the store listing. - `result(FlutterError)` with code `"url_construct_fail"` if the URL construction fails. ``` -------------------------------- ### Open Store Listing on Windows Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md Call the openStoreListing method with the microsoftStoreId for Windows. This parameter is conditional and required for this platform. ```dart await inAppReview.openStoreListing(microsoftStoreId: 'MyAppId'); ``` -------------------------------- ### openStoreListing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/AndroidInAppReviewPlugin.md Opens the application's store listing page in the Google Play Store. ```APIDOC ## openStoreListing ### Description Opens the application's store listing page in the Google Play Store. ### Method `openStoreListing(result: Result)` ### Behavior: This method is expected to handle the logic for opening the store listing. The specific implementation details are not provided in the source, but it should utilize the appropriate Android APIs to navigate the user to the app's page on the Play Store. ### Returns: `result.success(null)` on successful navigation or `result.error()` if an error occurs during the process. ``` -------------------------------- ### Platform detection with package:platform Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/types.md Use the Platform class from package:platform to detect the current operating system in Dart. ```dart final platform = LocalPlatform(); if (platform.isIOS) { print('Running on iOS'); } ``` -------------------------------- ### Invoke openStoreListing Method Channel (Android) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Invokes the 'openStoreListing' method on the channel for Android. This method takes no arguments. ```dart channel.invokeMethod('openStoreListing') ``` -------------------------------- ### Open Store Listing for iOS/macOS Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReview.md Opens the app's store listing on iOS or macOS. Requires the App Store ID. Use this when in-app review is not available or as a fallback. ```dart import 'package:in_app_review/in_app_review.dart'; final inAppReview = InAppReview.instance; await inAppReview.openStoreListing( appStoreId: '1234567890', // Your App Store ID ); ``` -------------------------------- ### Open Mac App Store Review Page Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/macOSInAppReviewPlugin.md Opens the Mac App Store to the review page for a given app store ID. It constructs a specific URL and uses NSWorkspace to open it. Minimal parameter validation is performed. ```swift case "openStoreListing": let storeId: String = call.arguments as! String guard let writeReviewURL = URL( string: "macappstore://apps.apple.com/app/id" + storeId + "?action=write-review") else { result( FlutterError( code: "url_construct_fail", message: "Failed to construct url", details: nil)) return } NSWorkspace.shared.open(writeReviewURL) result(nil) ``` -------------------------------- ### Open App Store Review Page (Swift) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/iOSInAppReviewPlugin.md Opens the App Store to the review page for a given store ID. Handles URL construction and uses appropriate methods for different iOS versions. Returns an error if the store ID is missing or URL construction fails. ```swift private func openStoreListing(storeId: String?, result: @escaping FlutterResult) { guard let storeId = storeId else { result(FlutterError(code: "no-store-id", message: "Your store id must be passed as the method channel's argument", details: nil)) return } let urlString = "https://apps.apple.com/app/id\(storeId)?action=write-review" guard let url = URL(string: urlString) else { result(FlutterError(code: "url-construct-fail", message: "Failed to construct url", details: nil)) return } if #available(iOS 10.0, *) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url) } result(nil) } ``` -------------------------------- ### InAppReviewPlatform.instance Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReviewPlatform.md Provides access to the current platform-specific in-app review implementation. It defaults to a MethodChannel implementation and can be overridden, typically for testing purposes. ```APIDOC ## InAppReviewPlatform.instance ### Description Provides access to the current platform-specific in-app review implementation. It defaults to a MethodChannel implementation and can be overridden, typically for testing purposes. ### Getter `static InAppReviewPlatform get instance` ### Setter `static set instance(InAppReviewPlatform instance)` ### Example ```dart final platform = InAppReviewPlatform.instance; final available = await platform.isAvailable(); ``` ### Example (Testing) ```dart InAppReviewPlatform.instance = MockInAppReviewPlatform(); ``` ``` -------------------------------- ### Request In-App Review Dialog in Kotlin Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/AndroidInAppReviewPlugin.md Requests to display the in-app review dialog. It checks for context and activity, then attempts to launch the review flow. Returns an error if the API is unavailable or an exception occurs. Success is indicated by null after the flow completes. ```kotlin private fun requestReview(result: Result) { Log.i(TAG, "requestReview: called") if (noContextOrActivity(result)) return try { val manager = ReviewManagerFactory.create(context!!) val request = manager.requestReviewFlow() request.addOnCompleteListener { task -> if (noContextOrActivity(result)) return@addOnCompleteListener if (task.isSuccessful) { Log.i(TAG, "onComplete: Successfully requested review flow") val info = task.result val flow = manager.launchReviewFlow(activity!!, info) flow.addOnCompleteListener { // The API does not indicate whether the user reviewed or if the dialog was shown. result.success(null) } } else { Log.w(TAG, "onComplete: Unsuccessfully requested review flow") result.error( "error", "In-App Review API unavailable", null ) } } } catch (e: Exception) { Log.e(TAG, "requestReview: error", e) result.error( "error", "An error occurred during the request review flow", null ) } } ``` -------------------------------- ### Mocking InAppReviewPlatform for Testing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/README.md Provides a mock implementation of the InAppReviewPlatform for use in testing environments. This allows simulating the behavior of the review process without actual platform interaction. ```dart import 'package:in_app_review_platform_interface/in_app_review_platform_interface.dart'; // For testing, set a mock platform class MockInAppReview extends InAppReviewPlatform { @override Future isAvailable() async => true; @override Future requestReview() async {} @override Future openStoreListing({ String? appStoreId, String? microsoftStoreId, }) async {} } // In test InAppReviewPlatform.instance = MockInAppReview(); ``` -------------------------------- ### Handle UnsupportedError on unsupported platforms Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/types.md Catch UnsupportedError if openStoreListing is called on a platform where it is not supported. ```dart try { await inAppReview.openStoreListing(); } on UnsupportedError catch (e) { print('Not supported: ${e.message}'); } ``` -------------------------------- ### Error Handling for In App Review Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/README.md Shows how to handle potential PlatformException or UnsupportedError during review requests. Falls back to opening the store listing on error. ```dart try { if (await inAppReview.isAvailable()) { await inAppReview.requestReview(); } } on PlatformException catch (e) { print('Platform error: ${e.code} - ${e.message}'); // Fallback to store listing await inAppReview.openStoreListing(appStoreId: '...'); } on UnsupportedError catch (e) { print('Not supported: ${e.message}'); } ``` -------------------------------- ### InAppReview Methods Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/README.md Provides an overview of the core methods available through the InAppReview plugin for checking review availability, requesting reviews, and opening store listings. ```APIDOC ## InAppReview Methods ### Description This section details the primary methods exposed by the InAppReview plugin that allow developers to interact with the in-app review and store listing functionalities. ### Methods - **`isAvailable()`** - **Description:** Checks if the in-app review functionality is available on the current device and platform. - **Returns:** `Future` - `true` if available, `false` otherwise. - **`requestReview()`** - **Description:** Prompts the user to review the application. This method is subject to platform-specific review quotas. - **Returns:** `Future` - **`openStoreListing({String? appStoreId, String? microsoftStoreId})`** - **Description:** Opens the application's listing in the respective app store. This method can take platform-specific IDs for targeting. - **Parameters:** - **`appStoreId`** (string) - Optional - The Apple App Store ID for iOS and macOS. - **`microsoftStoreId`** (string) - Optional - The Microsoft Store ID for Windows applications. - **Returns:** `Future` ### Usage Example ```dart final inAppReview = InAppReview.instance; if (await inAppReview.isAvailable()) { await inAppReview.requestReview(); } await inAppReview.openStoreListing(appStoreId: '1234567890', microsoftStoreId: 'MyAppId'); ``` ### Error Handling ```dart try { if (await inAppReview.isAvailable()) { await inAppReview.requestReview(); } } on PlatformException catch (e) { print('Platform error: ${e.code} - ${e.message}'); await inAppReview.openStoreListing(appStoreId: '...'); } on UnsupportedError catch (e) { print('Not supported: ${e.message}'); } ``` ``` -------------------------------- ### openStoreListing(storeId:result:) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/iOSInAppReviewPlugin.md Opens the App Store page for the application using the provided store ID. This is useful for directing users to the app's listing for reviews or updates. ```APIDOC ## openStoreListing(storeId:result:) ### Description Opens the App Store listing for the application in the App Store app. Requires a valid store ID. ### Method Signature `private func openStoreListing(storeId: String?, result: @escaping FlutterResult)` ### Parameters - **storeId** (`String?`) - The unique identifier for the app on the App Store. If nil or invalid, the behavior might lead to an error or default behavior. - **result** (`FlutterResult`) - A callback function to send the outcome of the operation back to Dart. Typically returns `nil` on success. ### Behavior Constructs a URL for the App Store and attempts to open it. The exact behavior for invalid or missing `storeId` is dependent on the underlying iOS APIs. ``` -------------------------------- ### iOS Version Adaptation with #available() Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/iOSInAppReviewPlugin.md This snippet demonstrates how to use Swift's `#available()` attribute to conditionally execute code based on the iOS version. It ensures compatibility by calling appropriate APIs for different iOS releases, preventing runtime errors on older versions. ```swift if #available(iOS 16.0, *) { // iOS 16+ code } else if #available(iOS 14.0, *) { // iOS 14-15 code } else if #available(iOS 10.3, *) { // iOS 10.3-13 code } else { // Unsupported } ``` -------------------------------- ### Request Review with Availability Check and PlatformException Handling Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/errors.md This pattern first checks if the review is available before attempting to request it. It includes a try-catch block to handle potential PlatformExceptions during the request. ```dart if (await inAppReview.isAvailable()) { try { await inAppReview.requestReview(); } on PlatformException catch (e) { print('requestReview failed: ${e.code}'); } } else { // Fallback to store listing await inAppReview.openStoreListing(appStoreId: '...'); } ``` -------------------------------- ### Launch URL Externally Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Private helper method to launch URLs, used on Windows for store links. It checks if the URL can be launched before attempting to open it in an external application. ```dart Future _launchUrl(String url) async { if (!await canLaunchUrlString(url)) return; await launchUrlString(url, mode: LaunchMode.externalNonBrowserApplication); } ``` -------------------------------- ### Android Build Configuration Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md Specifies Android build settings including compile SDK, min/target SDK versions, Java compatibility, and namespace. ```gradle android { compileSdkVersion 33 defaultConfig { minSdkVersion 21 targetSdkVersion 33 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } namespace "dev.britannio.in_app_review" } ``` -------------------------------- ### Invoke openStoreListing Method Channel (iOS/macOS) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Invokes the 'openStoreListing' method on the channel for iOS and macOS, passing the appStoreId as an argument. ```dart channel.invokeMethod('openStoreListing', appStoreId) ``` -------------------------------- ### Open Store Listing Source: https://github.com/britannio/in_app_review/blob/master/README.md Opens the app's store listing page. This is useful as a permanent call-to-action since it is not restricted by quotas. Provide the appropriate store ID for the target platform. ```dart import 'package:in_app_review/in_app_review.dart'; final InAppReview inAppReview = InAppReview.instance; inAppReview.openStoreListing(appStoreId: '...', microsoftStoreId: '...'); ``` -------------------------------- ### Android Method Channel Initialization Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md Initialize the method channel for Android using Kotlin. Ensure the method channel name matches the Dart side. ```kotlin MethodChannel( flutterPluginBinding.binaryMessenger, "dev.britannio.in_app_review" ) ``` -------------------------------- ### Open App Store Listing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Opens the store listing for the app. Use appStoreId for iOS/macOS and microsoftStoreId for Windows. Android uses no specific ID. ```dart Future openStoreListing({ String? appStoreId, String? microsoftStoreId, }) async { final bool isiOS = _platform.isIOS; final bool isMacOS = _platform.isMacOS; final bool isAndroid = _platform.isAndroid; final bool isWindows = _platform.isWindows; if (isiOS || isMacOS) { await _channel.invokeMethod( 'openStoreListing', ArgumentError.checkNotNull(appStoreId, 'appStoreId'), ); } else if (isAndroid) { await _channel.invokeMethod('openStoreListing'); } else if (isWindows) { ArgumentError.checkNotNull(microsoftStoreId, 'microsoftStoreId'); await _launchUrl( 'ms-windows-store://review/?ProductId=$microsoftStoreId', ); } else { throw UnsupportedError( 'Platform(${_platform.operatingSystem}) not supported', ); } } ``` -------------------------------- ### requestReview(_:) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/iOSInAppReviewPlugin.md Requests to display the in-app review dialog to the user. This method adapts its behavior based on the iOS version to use the most appropriate StoreKit API. ```APIDOC ## requestReview(_:) ### Description Requests to show the in-app review dialog. This method uses version-specific APIs to ensure compatibility across different iOS versions, from 10.3 up to the latest. ### Method Signature `private func requestReview(_ result: @escaping FlutterResult)` ### Parameters - **result** (`FlutterResult`) - A callback function to send the outcome of the review request back to Dart. Returns `nil` on success or a `FlutterError` if the feature is unavailable. ### Version-Specific Behavior - **iOS 16.0+:** Uses `AppStore.requestReview(in:)` with `UIWindowScene`. - **iOS 14.0-15.x:** Uses `SKStoreReviewController.requestReview(in:)` with `UIWindowScene`. - **iOS 10.3-13.x:** Uses the legacy `SKStoreReviewController.requestReview()`. - **iOS < 10.3:** Not supported; returns an error. ### Returns - `result(nil)` on successful initiation of the review prompt on supported iOS versions. - `result(FlutterError(code: "unavailable", message: "In-App Review unavailable", details: nil))` on iOS versions below 10.3. ``` -------------------------------- ### Invoke openStoreListing Method Channel Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/macOSInAppReviewPlugin.md Invokes the 'openStoreListing' method on the channel, passing the app's store ID as an argument to open its review page in the Mac App Store. ```dart channel.invokeMethod('openStoreListing', storeId) ``` -------------------------------- ### onMethodCall Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/AndroidInAppReviewPlugin.md Routes method calls from Dart to the appropriate handler methods within the plugin. ```APIDOC ## onMethodCall ### Description Routes method calls from Dart to appropriate handler methods. ### Method `onMethodCall(call: MethodCall, result: Result)` ### Parameters - **call** (`MethodCall`) - Represents the incoming method call from Dart. - **result** (`Result`) - Used to send the result or error back to Dart. ### Method Routing: - `"isAvailable"` → `isAvailable(result)` - `"requestReview"` → `requestReview(result)` - `"openStoreListing"` → `openStoreListing(result)` - Unknown methods → `result.notImplemented()` ### Logging: Logs each method name at INFO level. ``` -------------------------------- ### Mocking Platform Detection for Testing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/MethodChannelInAppReview.md Enables mocking of the platform detection utility to test platform-specific behaviors in isolation. This is crucial for ensuring correct logic execution on different operating systems. ```dart test('openStoreListing on iOS', () async { final mockPlatform = MockPlatform(); when(mockPlatform.isIOS).thenReturn(true); impl.platform = mockPlatform; // Test iOS-specific behavior }); ``` -------------------------------- ### Reliable Review Fallback Strategy Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/errors.md This approach uses `isAvailable()` to conditionally offer the in-app review but always provides `openStoreListing()` as a reliable fallback, acknowledging that `requestReview()` might fail silently due to rate limiting. ```dart // Good: Check availability before offering review option if (await inAppReview.isAvailable()) { // Can attempt in-app review, but no guarantee await inAppReview.requestReview(); } // Always provide store listing as reliable fallback await inAppReview.openStoreListing(appStoreId: '...'); ``` -------------------------------- ### Log Messages with NSLog (Swift) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/iOSInAppReviewPlugin.md Logs messages to the system log using NSLog. It can include optional details. All logs are sent to the system log at an INFO level. ```swift private func log(_ message: String, details: String? = nil) { if let details = details { NSLog("InAppReviewPlugin: \(message) \(details)") } else { NSLog("InAppReviewPlugin: \(message)") } } ``` ```swift log("requestReview", details: "iOS 16+") log("available") ``` -------------------------------- ### Android Google Play Store URL Format Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/README.md The standard URL format for linking to an application on the Google Play Store. The package name is automatically inferred and does not require a specific parameter. ```plaintext https://play.google.com/store/apps/details?id=com.example.app ``` -------------------------------- ### in_app_review_platform_interface pubspec.yaml Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md Defines the project name, version, and dependencies for the in_app_review platform interface. ```yaml name: in_app_review_platform_interface description: A common platform interface for the in_app_review plugin. version: 2.0.5 homepage: https://github.com/britannio/in_app_review/tree/master/in_app_review_platform_interface environment: sdk: '>=2.12.0 <4.0.0' flutter: ">=2.0.0" dependencies: flutter: sdk: flutter url_launcher: ^6.1.0 plugin_platform_interface: ^2.0.0 platform: ^3.0.0 dev_dependencies: flutter_test: sdk: flutter ``` -------------------------------- ### macOS Method Channel Initialization Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md Initialize the method channel for macOS using Swift. This establishes communication between Dart and the native macOS code. ```swift FlutterMethodChannel( name: "dev.britannio.in_app_review", binaryMessenger: registrar.messenger) ) ``` -------------------------------- ### Detect web platform with kIsWeb Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/types.md Use the kIsWeb constant from package:flutter/foundation.dart to check if the application is running on the web. ```dart import 'package:flutter/foundation.dart'; if (kIsWeb) { print('Running on web'); } ``` -------------------------------- ### iOS Method Channel Initialization Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md Initialize the method channel for iOS using Swift. This connects the Dart code to the native iOS implementation. ```swift FlutterMethodChannel(name: "dev.britannio.in_app_review", binaryMessenger: registrar.messenger()) ``` -------------------------------- ### Handle macOS InAppReviewPlugin Method Calls Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/macOSInAppReviewPlugin.md Routes incoming method calls from Dart to the appropriate handler methods within the plugin. Supports 'requestReview', 'isAvailable', and 'openStoreListing'. Unknown methods result in 'FlutterMethodNotImplemented'. ```swift public func handle( _ call: FlutterMethodCall, result: @escaping FlutterResult ) { switch call.method { case "requestReview": requestReview(result) case "isAvailable": isAvailable(result) case "openStoreListing": let storeId: String = call.arguments as! String guard let writeReviewURL = URL( string: "macappstore://apps.apple.com/app/id" + storeId + "?action=write-review") else { result( FlutterError( code: "url_construct_fail", message: "Failed to construct url", details: nil)) return } NSWorkspace.shared.open(writeReviewURL) result(nil) default: result(FlutterMethodNotImplemented) } } ``` -------------------------------- ### Fallback to Store Listing Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReview.md Demonstrates a fallback mechanism to open the store listing if the requestReview() method is unavailable. It checks availability and then either requests a review or opens the store listing. ```dart if (await inAppReview.isAvailable()) { await inAppReview.requestReview(); } else { // Fallback to store listing for devices without in-app review await inAppReview.openStoreListing( appStoreId: '1234567890', microsoftStoreId: 'YourAppId', ); } ``` -------------------------------- ### Check In-App Review Availability in Kotlin Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/AndroidInAppReviewPlugin.md Checks if the device supports in-app reviews by attempting to create a ReviewManager and request the review flow. Returns true if successful, false otherwise or if context is unavailable. Catches all exceptions. ```kotlin private fun isAvailable(result: Result) { Log.i(TAG, "isAvailable: called") if (noContextOrActivity()) { result.success(false) return } try { val manager = ReviewManagerFactory.create(context!!) val request = manager.requestReviewFlow() request.addOnCompleteListener { task -> if (task.isSuccessful) { // To our best knowledge, the plugin is compatible with this device result.success(true) } else { result.success(false) } } } catch (e: Exception) { Log.e(TAG, "isAvailable: error", e) result.success(false) } } ``` -------------------------------- ### Fallback Chain for Review Request Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/errors.md This pattern attempts to request a review and provides a fallback to opening the store listing if any exceptions occur. It catches both PlatformExceptions and general exceptions. ```dart try { if (await inAppReview.isAvailable()) { await inAppReview.requestReview(); } } on PlatformException catch (e) { print('Review not available: ${e.message}'); } catch (e) { print('Unexpected error: $e'); } // Always provide store listing as fallback await inAppReview.openStoreListing( appStoreId: '1234567890', microsoftStoreId: 'MyAppId', ); ``` -------------------------------- ### Migrate InAppReview Instance Declaration Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md This snippet illustrates the minor change required when migrating from version 1.x to 2.x of the InAppReview plugin, specifically for obtaining the plugin instance. The core instantiation remains the same but is now null-safe. ```dart // v1.x final inAppReview = InAppReview.instance; // v2.x (same, but now null-safe) final InAppReview inAppReview = InAppReview.instance; ``` -------------------------------- ### macOS Swift Package Manager Configuration Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/configuration.md Defines the Swift Package Manager configuration for the in_app_review plugin on macOS. ```swift // swift-tools-version:5.5 import PackageDescription let package = Package( name: "in_app_review", platforms: [ .macOS(.v10_14) ], products: [ .library(name: "in_app_review", targets: ["in_app_review"]) ], targets: [ .target( name: "in_app_review", dependencies: [], path: "Sources" ) ] ) ``` -------------------------------- ### Check In-App Review Availability (macOS) Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/macOSInAppReviewPlugin.md Checks if the device supports in-app review. Returns true for macOS 10.14+ and false otherwise. This check is performed inline. ```swift case "isAvailable": if #available(OSX 10.14, *) { result(true) } else { result(false) } ``` -------------------------------- ### MethodChannelInAppReview Implementation Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/MANIFEST.md Implementation of the InAppReviewPlatform interface using MethodChannel for communication between Dart and native code. ```APIDOC ## MethodChannelInAppReview Implementation ### Description Concrete implementation of `InAppReviewPlatform` that uses `MethodChannel` to communicate with native platform code (Android, iOS, macOS). ### Methods #### requestReview() ##### Description Invokes the native `requestReview` method via MethodChannel. ##### Method `Future requestReview()` ##### Parameters None ##### Response - **Success**: Completes with `void` on success. - **Error**: Throws an exception if the native call fails or returns an error. #### getPlatformReviewDialog() ##### Description Invokes the native `getPlatformReviewDialog` method via MethodChannel. ##### Method `Future getPlatformReviewDialog()` ##### Parameters None ##### Response - **Success**: Returns a `PlatformReviewDialog` object. - **Error**: Throws an exception if the native call fails or returns an error. #### isAvailable() ##### Description Invokes the native `isAvailable` method via MethodChannel. ##### Method `Future isAvailable()` ##### Parameters None ##### Response - **Success**: Returns `true` if available, `false` otherwise. - **Error**: Throws an exception if the native call fails or returns an error. ``` -------------------------------- ### requestReview Source: https://github.com/britannio/in_app_review/blob/master/_autodocs/api-reference/InAppReview.md Attempts to display the system's native review dialog. This method triggers the In-App Review API on Android and the equivalent on iOS/macOS, but returns immediately without indicating user interaction. ```APIDOC ## requestReview ### Description Attempts to display the system's native review dialog. This triggers the In-App Review API on Android and `requestReview()` on iOS/macOS. ### Method Future ### Parameters None ### Behavior: - Returns immediately without waiting for user interaction - Does not indicate whether the dialog was shown or the user submitted a review - Success return value `null` does not guarantee the dialog appeared - iOS and Android enforce strict rate quotas; excessive calls will result in the dialog not appearing ### Platform-Specific Behavior: - **Android:** Uses Google Play Core library's In-App Review API; only functional when app is published in Google Play Store internal test track, internal app sharing, or production - **iOS (16.0+):** Uses `AppStore.requestReview(in:)` for improved UX - **iOS (14.0-15.x):** Uses `SKStoreReviewController.requestReview(in:)` - **iOS (10.3-13.x):** Uses `SKStoreReviewController.requestReview()` without window scene - **macOS (13.0+):** Uses `AppStore.requestReview(in:)` with main window view controller - **macOS (10.14-12.x):** Uses `SKStoreReviewController.requestReview()` ### Quota Enforcement: Both platforms enforce daily/weekly quotas to avoid overwhelming users. Calling this frequently will not display the dialog after quota is exceeded. ### Best Practices: - Call only after meaningful user engagement (e.g., completing a game level, after several days of app use) - Do not trigger via UI buttons; use `openStoreListing()` for permanent user access instead - Check `isAvailable()` before calling, though the check succeeding does not guarantee the dialog will appear ### Returns A `Future` that completes when the operation finishes. ### Throws/Rejects Typically returns success even if dialog fails to appear due to quota or platform unavailability. Error may be returned on critical failures in native code. ### Example ```dart import 'package:in_app_review/in_app_review.dart'; final inAppReview = InAppReview.instance; // After user completes a task or milestone if (await inAppReview.isAvailable()) { await inAppReview.requestReview(); } ``` ```