Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Code example to load on particular page #87

Closed
Aravin opened this issue Apr 8, 2023 · 6 comments
Closed

Question: Code example to load on particular page #87

Aravin opened this issue Apr 8, 2023 · 6 comments

Comments

@Aravin
Copy link

Aravin commented Apr 8, 2023

Can you please share the Code example to load on a particular page on load?

can we use it in initState()?

@britannio
Copy link
Owner

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();
      }
    });
  }

@britannio
Copy link
Owner

ChatGPT actually provides an excellent response:

https://sharegpt.com/c/9OPOact

@britannio
Copy link
Owner

@Aravin
Copy link
Author

Aravin commented Apr 8, 2023

Thanks @britannio

@Aravin Aravin closed this as completed Apr 8, 2023
@Aravin
Copy link
Author

Aravin commented Apr 8, 2023

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);
      }
    });
  }

@britannio
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants