flutterdartrevenuecat

RevenueCat configuration error with Flutter


I initialize my code as below but I get this error :

There is an issue with your configuration. Check the underlying error for more details. There's a problem with your configuration. None of the products registered in the RevenueCat dashboard could be fetched from App Store Connect (or the StoreKit Configuration file if one is being used).

Code:

Future<void> main() async {
  runApp(const MyApp());

  await _configureSdk();
}

Future<void> _configureSdk() async {
  await Purchases.setLogLevel(LogLevel.debug);

  PurchasesConfiguration? configuration;

  if (Platform.isAndroid) {
    //
  } else if (Platform.isIOS) {
    configuration = PurchasesConfiguration('apikey');
  }

  if (configuration != null) {
    await Purchases.configure(configuration);
    print('configure');
 await RevenueCatUI.presentPaywallIfNeeded('Premium');
  }
}
await RevenueCatUI.presentPaywallIfNeeded('Premium');
ElevatedButton(
                onPressed: () async {
                  await RevenueCatUI.presentPaywallIfNeeded('Premium');
                },
                child: Text('purchases'))

I tried to open the paywall page in this way after clicking the button but I got the same error.


Solution

  • I think your configuration code needs to be called in your app state using the initState method instead of in main, something like this:

     @override
      void initState() {
        super.initState();
        _configureSdk();
      }
    
    
    Future<void> _configureSdk() async {
      await Purchases.setLogLevel(LogLevel.debug);
    
      PurchasesConfiguration? configuration;
    
      if (Platform.isAndroid) {
        //
      } else if (Platform.isIOS) {
        configuration = PurchasesConfiguration('apikey');
      }
    
      if (configuration != null) {
        await Purchases.configure(configuration);
        print('configure');
     await RevenueCatUI.presentPaywallIfNeeded('Premium');
      }
    }