void showPaywall() async {
setState(() {
// _isLoading = true;
});
CustomerInfo customerInfo = await Purchases.getCustomerInfo();
if (customerInfo.entitlements.all[entitlementID] != null &&
customerInfo.entitlements.all[entitlementID]?.isActive == true) {
setState(() {
// _isLoading = false;
alreadySubscribed();
});
} else {
Offerings? offerings;
try {
offerings = await Purchases.getOfferings();
} on PlatformException catch (error) {
errorMessage(error);
}
setState(() {
// _isLoading = false;
});
if (offerings == null || offerings.current == null) {
// offerings are empty, show a message to your user
} else {
// current offering is available, show paywall
if (!mounted) return;
await showModalBottomSheet(
useRootNavigator: true,
isDismissible: true,
isScrollControlled: true,
backgroundColor: Colors.black,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(25.0)),
),
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setModalState) {
return Paywall(
offering: offerings!.current!,
);
});
},
);
}
}
}
I think it shouldn’t make an error with context parameter since this method is in State object.
However, All of methods that receives context as BuildContext parameters are now making ‘undefined name ‘context”error.
It had no issues before and I’m sure I haven’t done anything that would make this kind of issue.
It could be something related to the framework or configuration kind of things, I don’t know…😂
Please let me know if you know how to fix this issue.
Thank you in advance!
I’ve tried cleaning cache files, reinstalling and downgrading flutter and dart extensions. and I found that this issue only occurs when methods outside of build needs BuildContext parameter.
2
Answers
I think you are missing the context key word.
only put:
context in the function parameter.
I hope it will work if don’t then provide more code.
I got this problem once and it was a problem with vsCode, but if you make ‘flutter analyze’ command (flutter compiler) in you folder and this error is shown your code are really wrong somewhere. So this is a first step to check if the problem is the code or the ide.