fix: 状态更新
This commit is contained in:
parent
8f347d9183
commit
4f09267b4b
@ -714,6 +714,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
|
||||
|
||||
/// 处理消息
|
||||
void _kr_handleMessage(KRMessageData message) {
|
||||
print('✅ [HomeController] EventBus message.kr_type${message.kr_type}');
|
||||
switch (message.kr_type) {
|
||||
case KRMessageType.kr_payment:
|
||||
kr_refreshAll();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:kaer_with_panels/app/services/kr_subscribe_service.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../../services/api_service/kr_subscribe_api.dart';
|
||||
@ -11,11 +11,13 @@ import '../../../utils/kr_common_util.dart';
|
||||
import '../../../localization/app_translations.dart';
|
||||
import '../../../utils/kr_log_util.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '';
|
||||
|
||||
/// 订单状态控制器(参考 Tauri 项目实现)
|
||||
class KROrderStatusController extends GetxController {
|
||||
/// API服务
|
||||
final KRSubscribeApi kr_subscribeApi = KRSubscribeApi();
|
||||
final KRSubscribeService kr_subscribeService = KRSubscribeService();
|
||||
|
||||
/// 支付是否成功
|
||||
final RxBool kr_isPaymentSuccess = false.obs;
|
||||
@ -273,8 +275,14 @@ class KROrderStatusController extends GetxController {
|
||||
kr_statusTitle.value = AppTranslations.kr_orderStatus.successTitle;
|
||||
kr_statusDescription.value = AppTranslations.kr_orderStatus.successDescription;
|
||||
kr_statusIcon.value = 'payment_success';
|
||||
// 发送支付成功事件
|
||||
KREventBus().kr_sendMessage(KRMessageType.kr_payment);
|
||||
|
||||
kr_subscribeService.kr_fetchAvailableSubscribes();
|
||||
// 🔧 修复:移除自动发送事件,改为在用户点击返回按钮时发送
|
||||
// 这样可以确保导航完成后才发送事件,避免旧控制器被销毁时收到事件
|
||||
// KREventBus().kr_sendMessage(KRMessageType.kr_payment);
|
||||
if (kDebugMode) {
|
||||
print('✅ [OrderStatus] 订单完成,等待用户返回首页时触发刷新');
|
||||
}
|
||||
break;
|
||||
|
||||
case kr_statusClose:
|
||||
|
||||
@ -8,6 +8,7 @@ import '../controllers/kr_order_status_controller.dart';
|
||||
import 'package:kaer_with_panels/app/routes/app_pages.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/hi_base_scaffold.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/hi_help_entrance.dart';
|
||||
import 'package:kaer_with_panels/app/utils/kr_event_bus.dart';
|
||||
|
||||
/// 订单状态视图
|
||||
class KROrderStatusView extends GetView<KROrderStatusController> {
|
||||
@ -102,6 +103,7 @@ class KROrderStatusView extends GetView<KROrderStatusController> {
|
||||
height: 48.h,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
KREventBus().kr_sendMessage(KRMessageType.kr_payment);
|
||||
// 返回到首页(清空导航栈)
|
||||
Get.offAllNamed(Routes.KR_HOME);
|
||||
},
|
||||
|
||||
@ -20,6 +20,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_stripe/flutter_stripe.dart';
|
||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
import 'dart:async';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:kaer_with_panels/app/model/response/kr_purchase_order_no.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/dialogs/hi_dialog.dart';
|
||||
import 'package:kaer_with_panels/app/services/iap/iap_pending_order_service.dart';
|
||||
@ -1057,20 +1058,27 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
KRCommonUtil.kr_hideLoading();
|
||||
KRCommonUtil.kr_showToast('购买请求失败,请重试');
|
||||
}
|
||||
} catch (e) {
|
||||
} on PlatformException catch (e) {
|
||||
KRCommonUtil.kr_hideLoading();
|
||||
// 识别是否是由于用户切出、弹窗被系统关闭引起的
|
||||
String errorMsg = e.toString();
|
||||
if (errorMsg.contains('storekit_error') || errorMsg.contains('canceled')) {
|
||||
// 这种属于用户行为导致的异常,不需要显示过于严重的“服务异常”
|
||||
print('ℹ️ [IAP] 支付流程被中断(用户退出或系统取消)');
|
||||
// 可以不报 Toast,或者报一个温和的提示
|
||||
KRCommonUtil.kr_showToast('支付已取消');
|
||||
} else {
|
||||
// 真正的程序/网络异常
|
||||
KRCommonUtil.kr_showToast('购买服务暂不可用,请重试');
|
||||
print('❌ [IAP] 严重异常: $e');
|
||||
|
||||
// --- 显式判断 iOS 取消异常 ---
|
||||
if (e.code == 'storekit2_purchase_cancelled') {
|
||||
print('ℹ️ [IAP] 确认:用户在 StoreKit2 弹窗中点击了取消');
|
||||
return; // 显式返回,不执行后续报错
|
||||
}
|
||||
|
||||
// --- 显式判断 旧版 StoreKit 取消异常 ---
|
||||
if (e.code == 'storekit_error' && (e.message?.contains('cancelled') ?? false)) {
|
||||
print('ℹ️ [IAP] 确认:用户在旧版 StoreKit 中取消');
|
||||
return;
|
||||
}
|
||||
|
||||
// 其他真正的平台异常
|
||||
KRCommonUtil.kr_showToast('购买服务暂不可用 (${e.code})');
|
||||
} catch (e) {
|
||||
// 处理非平台异常
|
||||
KRCommonUtil.kr_hideLoading();
|
||||
KRCommonUtil.kr_showToast('系统异常,请稍后重试');
|
||||
}
|
||||
} else {
|
||||
print('⚠️ 未知的支付类型: ${checkoutResponse.type}');
|
||||
|
||||
@ -159,7 +159,7 @@ class KRSubscribeService {
|
||||
}
|
||||
|
||||
/// 获取可用订阅列表
|
||||
Future<void> _kr_fetchAvailableSubscribes() async {
|
||||
Future<void> kr_fetchAvailableSubscribes() async {
|
||||
try {
|
||||
KRLogUtil.kr_i('开始获取可用订阅列表', tag: 'SubscribeService');
|
||||
|
||||
@ -479,7 +479,7 @@ class KRSubscribeService {
|
||||
void _kr_startPeriodicUpdate() {
|
||||
// 每5分钟更新一次可用订阅列表
|
||||
_kr_updateTimer = Timer.periodic(const Duration(seconds: 60), (timer) {
|
||||
_kr_fetchAvailableSubscribes();
|
||||
kr_fetchAvailableSubscribes();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 0.0.4+109
|
||||
version: 0.0.4+110
|
||||
|
||||
environment:
|
||||
sdk: ">=3.5.0 <4.0.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user