I can't find the cause of the error when setting up RevenueCat in my first application. Please help me find the cause of this error: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
I think the error is in this block:
PurchasesConfiguration configuration; print('2'); configuration = PurchasesConfiguration(StoreConfig.instance!.apiKey) ..appUserID = null ..observerMode = false;
It gives the following error:
Here is my user verification screen file. Which should be shown before the main screen:
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
late Timer timer;
@override
void initState() {
super.initState();
timer = Timer(const Duration(seconds: 10), () {
print('timer');
goToMain();
});
print('start');
SubscriptionsProvider.shared.addListener(() async {
if (!mounted) {
return;
}
// print(SubscriptionsProvider.shared.entitlementIsActive);
if (SubscriptionsProvider.shared.entitlementIsActive) {
goToMain();
} else {
print('else');
try {
SubscriptionsProvider.shared.subs =
await Purchases.getProducts([sub1Id, sub2Id, sub3Id]);
} on PlatformException catch (e) {
print('error');
goToMain();
}
if (SubscriptionsProvider.shared.subs == null ||
SubscriptionsProvider.shared.subs!.isEmpty) {
goToMain();
} else {
goToPayWall();
}
}
});
// initPlatformState();
}
goToMain() {
if (mounted) {
Navigator.of(context)
.pushReplacement(MaterialPageRoute(builder: (context) => Mainpage()));
}
}
goToPayWall() {
if (mounted) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => PayWallRevenueCat()));
}
}
@override
void dispose() {
timer.cancel();
SubscriptionsProvider.shared.removeListener(() {});
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xff000000), Color(0xff004BA4)])),
child:
const Scaffold(body: Center(child: CircularProgressIndicator())));
}
}
Additional file:
class SubscriptionsProvider extends ChangeNotifier {
// var subActive = false;
static SubscriptionsProvider shared = SubscriptionsProvider._();
bool entitlementIsActive = false;
String appUserID = '';
List<StoreProduct>? subs;
SubscriptionsProvider._() {
initPlatformState();
}
initPlatformState() async {
// Enable debug logs before calling `configure`.
print('1');
await Purchases.setLogLevel(LogLevel.debug);
PurchasesConfiguration configuration;
print('2');
configuration = PurchasesConfiguration(StoreConfig.instance!.apiKey)
..appUserID = null
..observerMode = false;
// ..usesStoreKit2IfAvailable = true;
await Purchases.configure(configuration);
print('3');
appUserID = await Purchases.appUserID;
print('4');
Purchases.addCustomerInfoUpdateListener((customerInfo) async {
print('Purchases.addCustomerInfoUpdateListener started');
appUserID = await Purchases.appUserID;
CustomerInfo customerInfo = await Purchases.getCustomerInfo();
(customerInfo.entitlements.all[entitlementID] != null &&
customerInfo.entitlements.all[entitlementID]!.isActive)
? entitlementIsActive = true
: entitlementIsActive = false;
notifyListeners();
});
}
}