Flutter 在颤振中显示所有RevenueCat PurchaseErrorCode代码

Flutter 在颤振中显示所有RevenueCat PurchaseErrorCode代码,flutter,revenuecat,Flutter,Revenuecat,我需要在我的Flatter应用程序中捕获所有列出的PurchaseErrorCode错误代码,以便我可以相应地响应它们 目前,我只能捕获“userCancelled”,对于其他所有内容,我只能报告在标准PlatformException代码、消息和详细信息属性中返回的信息,而不知道它们将包含什么 try { // Code to make purchase.. } on PlatformException catch (e) { if (!(e.details as Map)["u

我需要在我的Flatter应用程序中捕获所有列出的PurchaseErrorCode错误代码,以便我可以相应地响应它们

目前,我只能捕获“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中公开,但我无法在Flatter/Dart中获得它们-我缺少了什么?

我开发了RevenueCat Flatter插件,不久前我在GitHub上创建了一个问题来跟踪它()。很抱歉,在颤振错误处理方面还有一些改进的余地

发送平台异常时,我们将错误代码作为字符串传递:

result.error(error.getCode().ordinal()+“”,error.getMessage(),userInfoMap)

太糟糕了,我们不能只传递一个int作为第一个参数,我们必须传递一个字符串,我想我们可以在
userInfoMap
中传递它。但是现在,由于我们还没有向enum提供错误代码,您必须在代码中执行类似的操作:

enum purchaserrorcode{
未知错误,
采购取消错误,
存储问题错误,
PurchaseNotAllowedError,
采购无效错误,
ProductNotAvailableForPurchaseError,
ProductAlreadyPurchasedError,
ReceiptalReadyUseError,
无效接收错误,
MissingReceiptFileError,
网络错误,
无效证书错误,
意外的后端响应错误,
接收到其他订阅错误,
InvalidAppUserId错误,
操作错误,
未知的背景错误,
许可证不足错误
}
试一试{
}平台上异常捕获(e){
PurchaseErrorCode errorCode=PurchaseErrorCode.values[int.parse(e.code)];
开关(错误代码){
案例PurchaseErrorCode.Unknown错误:
案例PurchaseErrorCode.PurchaseCancelled错误:
案例PurchaseErrorCode.StoreProblemError:
//添加其余的案例
}
}
当您执行
e.details
时,您还可以访问包含错误代码名称的
readableErrorCode
;以及一条
隐藏的错误消息
,希望能帮助您调试任何问题


我希望这有帮助

上一个答案中提到的问题已经解决,在1.0.0版之后,您可以这样处理:

试试看{
PurchaserInfo PurchaserInfo=等待购买。purchasePackage(package);
}平台上异常捕获(e){
var errorCode=purchaseErrorHelper.getErrorCode(e);
如果(errorCode==PurchaseErrorCode.PurchaseCanceledError){
打印(“用户取消”);
}else if(errorCode==PurchaseErrorCode.purchaseNotAllowedError){
打印(“不允许用户购买”);
}
}

是否有其他例外情况不是平台例外?使用try-and-catch-and-see谢谢,但是RevenueCat文档说所有异常都将作为PlatformException抛出。我无法使用try..catch检查所有可能的RevenueCat异常,因为我无法触发它们。在我看来,您真正想知道的是RevenueCat的
平台异常中包含的错误代码是什么。我说得对吗?是的,但在Dart中以枚举或等效项的形式公开,这样我就不必硬编码它们,也不必冒将来被破坏的风险。作为一个临时解决方案,我可以构建自己的枚举(甚至解析描述),但这并不理想。其他语言的API公开了它们。。。