Question

Flutter Purchases.restorePurchases()

  • 28 October 2023
  • 1 reply
  • 56 views

Userlevel 1
Badge +4

Hi Everyone,
For some reason in my app, during the registration process, and while updating user details, the paywall pops up, which prompts the user to buy before their setup is complete.

That of course generates an RCAnonymous userId in RevenueCat and my firestore database. Prompting the users to navigate to the subscription page would work but relys on them remembering to do it, even after sending reminder emails.

Is it possible to call Purchases.restorePurchase() during the FirebaseAuth login flow, after the user has successfully logged in and the user details have been retrieved?

Can I call this...

  _restore() async {
setState(() {
isLoading = true;
});

try {
await Purchases.restorePurchases();
appData.appUserID = await Purchases.appUserID;
} on PlatformException catch (e) {
await showDialog(
context: context,
builder: (BuildContext context) => ShowDialogToDismiss(
title: "Error",
content: e.message ?? "Unknown error",
buttonText: 'OK'));
}

setState(() {
isLoading = false;
});
}

Inside this function…

  Future<void> checkRCLogin(String uid) async {
// Later log in provided user Id
await Purchases.logIn(uid!);
await _restore();

// .shared.logIn(<my_app_user_id>) { (customerInfo, created, error) in
// customerInfo updated for my_app_user_id
}

During the login event, here?
 

setState(() {
showSpinner = true;
});
try {
final user = await _auth.signInWithEmailAndPassword(
email: email!, password: password!);

String uid = _auth.currentUser!.uid;

checkRCLogin(uid);
...
}

Is there a problem calling Purchases.restorePurchases() every time a user logs in?

Thanks in advance.

P.S. I’m also not sure why the paywall pops up during the setup process. I only call it from the home screen after the user has logged in.

Michael C.


1 reply

Userlevel 1
Badge +4

Fixed by adding a Widget tree containing subscription info and a restore button. The paywall is fired by an ElevatedButton and once a subscription is purchased the singleton kicks in and everything aligns.


I use a boolean hasSubs set to true if a subscription is found, then show the main content.


So far so good on a real device in dev mode. Waiting for the build to pass review then try it in real time.

 

Michael C.

Reply