fix: 处理order_status异步

This commit is contained in:
2025-12-24 17:08:59 -08:00
parent 7740b46fa6
commit 18e932e738
9 changed files with 187 additions and 136 deletions
@@ -101,71 +101,70 @@ class KROrderStatusView extends GetView<KROrderStatusController> {
SizedBox(
width: double.infinity,
height: 48.h,
child: ElevatedButton(
onPressed: () async {
// 1. 先触发业务层的数据刷新请求(确保内存数据是最新的)
// 假设 kr_subscribeService.kr_fetchAvailableSubscribes() 返回 Future
await controller.kr_subscribeService.kr_fetchAvailableSubscribes();
child: Obx(() {
// 获取当前的刷新状态
final bool isRefreshing = controller.kr_isRefreshingData.value;
// 2. 发送事件总线通知
KREventBus().kr_sendMessage(KRMessageType.kr_payment);
return ElevatedButton(
// 如果正在刷新数据,则禁用点击(设为 null)
onPressed: isRefreshing
? null
: () async {
// 1. 先触发业务层的数据刷新请求
controller.kr_subscribeService.kr_fetchAvailableSubscribes();
// 3. 关键:稍微延迟一下再执行 offAllNamed
// 这样可以确保 EventBus 的消息被其他观察者消费完毕,并让网络请求有时间在内存中沉淀
await Future.delayed(const Duration(milliseconds: 100));
// 4. 返回到首页(清空导航栈)
Get.offAllNamed(Routes.KR_HOME);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.r),
// 2. 发送事件总线通知
KREventBus().kr_sendMessage(KRMessageType.kr_payment);
// 4. 返回到首页
Get.offAllNamed(Routes.KR_HOME);
},
style: ElevatedButton.styleFrom(
backgroundColor: isRefreshing ? Colors.grey[300] : Colors.white,
foregroundColor: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.r),
),
elevation: 0,
// 禁用时的样式
disabledBackgroundColor: Colors.grey[200],
),
elevation: 0,
),
child: Text(
AppTranslations.kr_orderStatus.backToHome,
style: KrAppTextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.black,
child: isRefreshing
? Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Loading 动画
SizedBox(
height: 20.w,
width: 20.w,
child: CircularProgressIndicator(
color: Colors.black54,
strokeWidth: 2.w,
),
),
SizedBox(width: 12.w),
// 正在刷新的提示文字
Text(
"订阅更新中...", // 或者从 AppTranslations 获取
style: KrAppTextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.black54,
),
),
],
)
: Text(
AppTranslations.kr_orderStatus.backToHome,
style: KrAppTextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
);
}),
),
SizedBox(height: 12.h),
// 查看订阅按钮
// SizedBox(
// width: double.infinity,
// height: 48.h,
// child: OutlinedButton(
// onPressed: () {
// // 返回到首页并切换到订阅页面
// Get.offAllNamed('/');
// // 可以通过事件总线发送消息切换tab
// },
// style: OutlinedButton.styleFrom(
// foregroundColor: Theme.of(Get.context!).primaryColor,
// side: BorderSide(
// color: Theme.of(Get.context!).primaryColor,
// width: 1.5,
// ),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(12.r),
// ),
// ),
// child: Text(
// AppTranslations.kr_orderStatus.viewSubscription,
// style: KrAppTextStyle(
// fontSize: 16,
// fontWeight: FontWeight.w600,
// color: Colors.black,
// ),
// ),
// ),
// ),
],
),
);