Closed Aravin closed 1 year ago
https://github.com/britannio/in_app_review#requestreview demonstrates how to use the plugin.
This example attempts to show the popup after the first frame has been displayed.
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
final InAppReview inAppReview = InAppReview.instance;
if (await inAppReview.isAvailable()) {
inAppReview.requestReview();
}
});
}
ChatGPT actually provides an excellent response:
https://www.phind.com/search?cache=8564ce05-5124-486c-a91e-48e2cf8b9d96 provides a less direct response but with links to sources such as https://stackoverflow.com/questions/65399583/use-of-in-app-review-package-in-flutter
Thanks @britannio
And my code looks like this
@override
void initState() {
saveOnboardingSettings();
super.initState();
(<T>(T? o) => o!)(WidgetsBinding.instance).addPostFrameCallback((_) async {
try {
final isAvailable = await _inAppReview.isAvailable();
setState(() {
_availability = isAvailable && !Platform.isAndroid
? Availability.available
: Availability.unavailable;
_inAppReview.requestReview();
});
} catch (_) {
setState(() => _availability = Availability.unavailable);
}
});
}
Nice. Bear in mind that you may be able to replace (<T>(T? o) => o!)(WidgetsBinding.instance)
with WidgetsBinding.instance
as it was just a precaution to ensure the example app compiled on older versions of Flutter. Also, you likely don't need the _availability
variable, or if you do, it shouldn't contain the Platform.isAndroid
case.
Can you please share the Code example to load on a particular page on load?
can we use it in initState()?