我需要在我的 Flutter 应用程序中捕获所有列出的 PurchasesErrorCode 错误代码,以便我可以相应地响应它们。
目前我只能捕获“userCancelled”,对于其他一切我只能报告标准 PlatformException 代码、消息和详细信息属性中返回的信息,而不知道它们将包含什么。
try {
// Code to make purchase..
} on PlatformException catch (e) {
if (!(e.details as Map)["userCancelled"]) {
// Here I need a comprehensive switch statement so I can
// retry where appropriate/control what messages the user sees
String reason = '';
(e.details as Map).forEach((k,v) => reason += '$k => $v');
showError(context, 'Error', '${e.code} : ${e.message}');
} else {
showError(context, 'Purchase Cancelled', 'Your purchase was not completed, you have not been charged.');
}
}
这些代码在 IOS/Swift 和 Android/Kotlin 中公开,但我无法在 Flutter/Dart 中获取它们——我错过了什么?