fix: 状态更新

This commit is contained in:
speakeloudest 2025-12-17 23:17:14 -08:00
parent 8f347d9183
commit 4f09267b4b
6 changed files with 37 additions and 18 deletions

View File

@ -714,6 +714,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver {
/// ///
void _kr_handleMessage(KRMessageData message) { void _kr_handleMessage(KRMessageData message) {
print('✅ [HomeController] EventBus message.kr_type${message.kr_type}');
switch (message.kr_type) { switch (message.kr_type) {
case KRMessageType.kr_payment: case KRMessageType.kr_payment:
kr_refreshAll(); kr_refreshAll();

View File

@ -1,6 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:io' show Platform; import 'dart:io' show Platform;
import 'package:kaer_with_panels/app/services/kr_subscribe_service.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import '../../../services/api_service/kr_subscribe_api.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 '../../../localization/app_translations.dart';
import '../../../utils/kr_log_util.dart'; import '../../../utils/kr_log_util.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import '';
/// Tauri /// Tauri
class KROrderStatusController extends GetxController { class KROrderStatusController extends GetxController {
/// API服务 /// API服务
final KRSubscribeApi kr_subscribeApi = KRSubscribeApi(); final KRSubscribeApi kr_subscribeApi = KRSubscribeApi();
final KRSubscribeService kr_subscribeService = KRSubscribeService();
/// ///
final RxBool kr_isPaymentSuccess = false.obs; final RxBool kr_isPaymentSuccess = false.obs;
@ -273,8 +275,14 @@ class KROrderStatusController extends GetxController {
kr_statusTitle.value = AppTranslations.kr_orderStatus.successTitle; kr_statusTitle.value = AppTranslations.kr_orderStatus.successTitle;
kr_statusDescription.value = AppTranslations.kr_orderStatus.successDescription; kr_statusDescription.value = AppTranslations.kr_orderStatus.successDescription;
kr_statusIcon.value = 'payment_success'; 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; break;
case kr_statusClose: case kr_statusClose:

View File

@ -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/routes/app_pages.dart';
import 'package:kaer_with_panels/app/widgets/hi_base_scaffold.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/widgets/hi_help_entrance.dart';
import 'package:kaer_with_panels/app/utils/kr_event_bus.dart';
/// ///
class KROrderStatusView extends GetView<KROrderStatusController> { class KROrderStatusView extends GetView<KROrderStatusController> {
@ -102,6 +103,7 @@ class KROrderStatusView extends GetView<KROrderStatusController> {
height: 48.h, height: 48.h,
child: ElevatedButton( child: ElevatedButton(
onPressed: () { onPressed: () {
KREventBus().kr_sendMessage(KRMessageType.kr_payment);
// //
Get.offAllNamed(Routes.KR_HOME); Get.offAllNamed(Routes.KR_HOME);
}, },

View File

@ -20,6 +20,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_stripe/flutter_stripe.dart'; import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:in_app_purchase/in_app_purchase.dart'; import 'package:in_app_purchase/in_app_purchase.dart';
import 'dart:async'; 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/model/response/kr_purchase_order_no.dart';
import 'package:kaer_with_panels/app/widgets/dialogs/hi_dialog.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'; 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_hideLoading();
KRCommonUtil.kr_showToast('购买请求失败,请重试'); KRCommonUtil.kr_showToast('购买请求失败,请重试');
} }
} catch (e) { } on PlatformException catch (e) {
KRCommonUtil.kr_hideLoading(); KRCommonUtil.kr_hideLoading();
//
String errorMsg = e.toString(); // --- iOS ---
if (errorMsg.contains('storekit_error') || errorMsg.contains('canceled')) { if (e.code == 'storekit2_purchase_cancelled') {
// print(' [IAP] 确认:用户在 StoreKit2 弹窗中点击了取消');
print(' [IAP] 支付流程被中断(用户退出或系统取消)'); return; //
// Toast
KRCommonUtil.kr_showToast('支付已取消');
} else {
// /
KRCommonUtil.kr_showToast('购买服务暂不可用,请重试');
print('❌ [IAP] 严重异常: $e');
} }
// --- 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 { } else {
print('⚠️ 未知的支付类型: ${checkoutResponse.type}'); print('⚠️ 未知的支付类型: ${checkoutResponse.type}');

View File

@ -159,7 +159,7 @@ class KRSubscribeService {
} }
/// ///
Future<void> _kr_fetchAvailableSubscribes() async { Future<void> kr_fetchAvailableSubscribes() async {
try { try {
KRLogUtil.kr_i('开始获取可用订阅列表', tag: 'SubscribeService'); KRLogUtil.kr_i('开始获取可用订阅列表', tag: 'SubscribeService');
@ -479,7 +479,7 @@ class KRSubscribeService {
void _kr_startPeriodicUpdate() { void _kr_startPeriodicUpdate() {
// 5 // 5
_kr_updateTimer = Timer.periodic(const Duration(seconds: 60), (timer) { _kr_updateTimer = Timer.periodic(const Duration(seconds: 60), (timer) {
_kr_fetchAvailableSubscribes(); kr_fetchAvailableSubscribes();
}); });
} }

View File

@ -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 # 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 # 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. # 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: environment:
sdk: ">=3.5.0 <4.0.0" sdk: ">=3.5.0 <4.0.0"