flutter_stripe
flutter_stripe copied to clipboard
There is no way to check if a publishable key is set or not
Is your feature request related to a problem? (please describe)
The publishable key is the only required value that needs to be set before we can use the package. The problem is that the current implementation will just throw a Null check operator used on a null value
when the app is in release mode.
/// Retrieves the publishable API key.
static String get publishableKey {
assert(instance._publishableKey != null, // <-- this doesn't run in release mode
'A publishableKey is required and missing');
return instance._publishableKey!;
}
In our use case, the publishable key comes from an external service, since the key depends on a couple of factors. Because of this, we can not set the publishable key immediately when the app starts. The risk here is that we might call a method within the Stripe package, while the key is not set yet (e.g. because the external service request to retrieve the keys failed).
Describe the solution you'd like I want to check if the publishable key is defined by returning a nullable string or a meaningful error so I can respond with an appropriate action when the key is not defined.
Good point - thanks!