Hello everyone,
I hope you're all doing well. I'm currently working on a Flutter application that integrates Firebase for authentication and utilizes Riverpod and GoRouter for state management and navigation. While I've successfully implemented RevenueCat in previous projects, I'm encountering challenges with this particular setup.
Current Setup:
-
Flutter
-
Firebase Authentication
-
Riverpod
-
GoRouter
-
RevenueCat with Firebase integration
Issues Faced:
-
Paywall v2 Not Detected: In my previous applications, Paywall v1 functioned without issues. However, after transitioning to Paywall v2, the paywall isn't being detected or displayed as expected. I've reviewed the documentation but haven't found a solution.
-
User Management and Exception Handling: I'm uncertain about the best practices for managing users and handling exceptions post-purchase. Specifically, I'm looking for guidance on:
-
Ensuring that once a user completes a purchase, their entitlements are correctly recognized and maintained.
-
Handling scenarios where a user logs out and logs back in, ensuring their purchase history and entitlements persist.
-
Managing errors and exceptions that might arise during the purchase process to provide a seamless user experience.
-
I've integrated the RevenueCat Firebase plugin, and the initial setup appears correct. However, these issues are hindering the app's functionality, and I aim to make the application production-ready.
Any insights, suggestions, or guidance would be immensely appreciated. Thank you in advance for your support!
This is some of my code:
try {
print('💰 Paywall: Verificando estado premium');
// Verificar con RevenueCat
final customerInfo = await Purchases.getCustomerInfo();
final hasActiveEntitlement = customerInfo.entitlements.active.isNotEmpty;
print('📊 Paywall: Estado de suscripción:');
print(' - Entitlements activos: ${customerInfo.entitlements.active.keys.join(", ")}');
print(' - Es premium: $hasActiveEntitlement');
if (hasActiveEntitlement) {
// Actualizar Firestore
await FirebaseFirestore.instance.collection('users').doc(user.uid).update({
'onboardingCompleted': true,
'premiumStatus': true,
'lastPremiumCheck': FieldValue.serverTimestamp(),
});
if (mounted) {
print('✅ Paywall: Usuario premium verificado, redirigiendo a basescreen');
context.go('/basescreen');
}
} else {
print('⚠️ Paywall: Usuario aún no es premium, mostrando paywall');
await RevenueCatUI.presentPaywallIfNeeded(
"BlissPaywall2",
offering: null,
displayCloseButton: true,
);
}
} catch (e) {
print('❌ Paywall: Error: $e');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error al procesar el estado premium: $e')),
);
}
} finally {
if (mounted) {
setState(() {
_isLocalLoading = false;
});
}
}
}
