fix: 处理order_status异步

This commit is contained in:
2025-12-22 18:15:41 -08:00
parent 83d201b78d
commit 7740b46fa6
6 changed files with 206 additions and 198 deletions
@@ -54,7 +54,7 @@ class HIHelpView extends GetView<HIHelpController> implements HasSwipeConfig {
controller: scrollController, controller: scrollController,
child: ListView.builder( child: ListView.builder(
controller: scrollController, controller: scrollController,
padding: EdgeInsets.only(left: 40.w - 20, right: 40.w), padding: EdgeInsets.only(left: 40.w, right: 40.w),
itemCount: controller.kr_messages.length, itemCount: controller.kr_messages.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final message = controller.kr_messages[index]; final message = controller.kr_messages[index];
@@ -16,34 +16,39 @@ class KRInviteView extends GetView<KRInviteController> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isKeyboardVisible = MediaQuery.of(context).viewInsets.bottom > 0; // 监听键盘高度,仅用于控制悬浮按钮的可见性
final bool isKeyboardVisible = MediaQuery.of(context).viewInsets.bottom > 0;
return HIBaseScaffold( return HIBaseScaffold(
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
// 1. child 的根组件使用 Stack,以允许绝对定位的组件(如 HIHelpEntrance)正常工作 child: GestureDetector(
// 允许点击空白处收起键盘
onTap: () => FocusScope.of(context).unfocus(),
behavior: HitTestBehavior.translucent,
child: Stack( child: Stack(
children: [ children: [
SingleChildScrollView( // 1. 背景层/滚动层
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag, Positioned.fill(
child: SingleChildScrollView(
// 保持手动管理,增强稳定性
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
child: Padding( child: Padding(
padding: EdgeInsets.symmetric(horizontal: 40.w), padding: EdgeInsets.symmetric(horizontal: 40.w),
// 3. 使用一个内层 Column 来组织内容
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SizedBox(height: 20.w),
// 🟢 第一行:奖励说明 // 🟢 第一行:奖励说明
Container( Container(
width: double.infinity, width: double.infinity,
padding: padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 20.w),
EdgeInsets.symmetric(horizontal: 16.w, vertical: 20.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(25.r), borderRadius: BorderRadius.circular(25.r),
), ),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [ children: [
KrLocalImage( KrLocalImage(
imageName: 'hi-home-logo', imageName: 'hi-home-logo',
@@ -69,8 +74,7 @@ class KRInviteView extends GetView<KRInviteController> {
SizedBox(height: 26.w), SizedBox(height: 26.w),
// 🟢 第二行:我的邀请码 // 🟢 第二行:我的邀请码
Container( Container(
padding: padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 2.w),
EdgeInsets.symmetric(horizontal: 4.w, vertical: 2.w),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all(color: Colors.white, width: 2.0), border: Border.all(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(1000.r), borderRadius: BorderRadius.circular(1000.r),
@@ -123,18 +127,10 @@ class KRInviteView extends GetView<KRInviteController> {
'点击此处进入下载页面\n' '点击此处进入下载页面\n'
'或在浏览器输入hifastvpn.com下载#'; '或在浏览器输入hifastvpn.com下载#';
if (GetPlatform.isIOS) { if (GetPlatform.isIOS) {
Share.share( Share.share(text, subject: '直接分享Hi快VPN邀请链接');
text,
subject: '直接分享Hi快VPN邀请链接',
);
} else { } else {
Clipboard.setData( Clipboard.setData(ClipboardData(text: text));
ClipboardData( KRCommonUtil.kr_showToast(AppTranslations.kr_invite.inviteCodeCopied);
text: text),
);
KRCommonUtil.kr_showToast(
AppTranslations.kr_invite.inviteCodeCopied,
);
} }
} }
}, },
@@ -157,36 +153,34 @@ class KRInviteView extends GetView<KRInviteController> {
), ),
), ),
SizedBox(height: 8.h), SizedBox(height: 8.h),
TextField( // 使用 RepaintBoundary 隔离,减少父级重绘对 TextField 的影响
RepaintBoundary(
child: TextField(
controller: controller.otherInviteCodeController, controller: controller.otherInviteCodeController,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: const TextStyle( style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
color: Colors.white, fontWeight: FontWeight.bold),
decoration: InputDecoration( decoration: InputDecoration(
hintText: '填入邀请人邀请码兑换免费时长...', hintText: '填入邀请人邀请码兑换免费时长...',
hintStyle: const TextStyle(color: Color(0xFFA6A6A6)), hintStyle: const TextStyle(color: Color(0xFFA6A6A6)),
filled: true, filled: true,
fillColor: Colors.transparent, fillColor: Colors.transparent,
contentPadding: contentPadding: EdgeInsets.symmetric(horizontal: 22.w),
EdgeInsets.symmetric(horizontal: 22.w),
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(1000.r), borderRadius: BorderRadius.circular(1000.r),
borderSide: const BorderSide( borderSide: const BorderSide(color: Colors.white, width: 2.0),
color: Colors.white, width: 2.0),
), ),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(1000.r), borderRadius: BorderRadius.circular(1000.r),
borderSide: const BorderSide( borderSide: const BorderSide(color: Colors.white, width: 2.0),
color: Colors.white, width: 2.0),
), ),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(1000.r), borderRadius: BorderRadius.circular(1000.r),
borderSide: const BorderSide( borderSide: const BorderSide(color: Colors.white, width: 2.0),
color: Colors.white, width: 2.0),
), ),
constraints: BoxConstraints(maxHeight: 50.h), constraints: BoxConstraints(maxHeight: 50.h),
), ),
), ),
),
SizedBox(height: 10.w), SizedBox(height: 10.w),
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
@@ -198,9 +192,7 @@ class KRInviteView extends GetView<KRInviteController> {
borderRadius: BorderRadius.circular(1000.r), borderRadius: BorderRadius.circular(1000.r),
), ),
), ),
onPressed: () { onPressed: () => controller.kr_handleBindInviteCode(),
controller.kr_handleBindInviteCode();
},
child: Text( child: Text(
'保存', '保存',
style: TextStyle( style: TextStyle(
@@ -213,17 +205,23 @@ class KRInviteView extends GetView<KRInviteController> {
), ),
], ],
), ),
// 4. 在可滚动区域的末尾添加一个占位边距,防止内容被 HIHelpEntrance 遮挡 // 底部留白,确保键盘弹出后能滚过遮挡区域
SizedBox(height: 80.w), // 这个高度可以根据 HIHelpEntrance 的实际高度进行微调 SizedBox(height: 250.w),
], ],
), ),
), ),
), ),
),
// 5. 将 HIHelpEntrance 作为 Stack 的直接子元素,它将恢复其原有的绝对定位能力 // 2. 🟢 修正:为了防止遮挡输入框,当键盘弹出时彻底隐藏该悬浮组件
if (!isKeyboardVisible) const HIHelpEntrance(), // 使用 Visibility 配合 maintainState,避免因组件销毁导致的定位状态丢失
Visibility(
visible: !isKeyboardVisible,
child: const HIHelpEntrance(),
),
], ],
), ),
),
); );
} }
} }
@@ -84,7 +84,7 @@ class KRMessageView extends GetView<KRMessageController>
child: ListView.builder( child: ListView.builder(
controller: scrollController, controller: scrollController,
padding: padding:
EdgeInsets.only(left: 40.w - 20, right: 40.w), EdgeInsets.only(left: 40.w, right: 40.w),
itemCount: controller.kr_messages.length, itemCount: controller.kr_messages.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final message = controller.kr_messages[index]; final message = controller.kr_messages[index];
@@ -276,7 +276,7 @@ class KROrderStatusController extends GetxController {
kr_statusDescription.value = AppTranslations.kr_orderStatus.successDescription; kr_statusDescription.value = AppTranslations.kr_orderStatus.successDescription;
kr_statusIcon.value = 'payment_success'; kr_statusIcon.value = 'payment_success';
kr_subscribeService.kr_fetchAvailableSubscribes(); // kr_subscribeService.kr_fetchAvailableSubscribes();
// 🔧 修复:移除自动发送事件,改为在用户点击返回按钮时发送 // 🔧 修复:移除自动发送事件,改为在用户点击返回按钮时发送
// 这样可以确保导航完成后才发送事件,避免旧控制器被销毁时收到事件 // 这样可以确保导航完成后才发送事件,避免旧控制器被销毁时收到事件
// KREventBus().kr_sendMessage(KRMessageType.kr_payment); // KREventBus().kr_sendMessage(KRMessageType.kr_payment);
@@ -102,9 +102,19 @@ class KROrderStatusView extends GetView<KROrderStatusController> {
width: double.infinity, width: double.infinity,
height: 48.h, height: 48.h,
child: ElevatedButton( child: ElevatedButton(
onPressed: () { onPressed: () async {
// 1. 先触发业务层的数据刷新请求(确保内存数据是最新的)
// 假设 kr_subscribeService.kr_fetchAvailableSubscribes() 返回 Future
await controller.kr_subscribeService.kr_fetchAvailableSubscribes();
// 2. 发送事件总线通知
KREventBus().kr_sendMessage(KRMessageType.kr_payment); KREventBus().kr_sendMessage(KRMessageType.kr_payment);
// 返回到首页(清空导航栈)
// 3. 关键:稍微延迟一下再执行 offAllNamed
// 这样可以确保 EventBus 的消息被其他观察者消费完毕,并让网络请求有时间在内存中沉淀
await Future.delayed(const Duration(milliseconds: 100));
// 4. 返回到首页(清空导航栈)
Get.offAllNamed(Routes.KR_HOME); Get.offAllNamed(Routes.KR_HOME);
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
+1 -1
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+112 version: 0.0.4+113
environment: environment:
sdk: ">=3.5.0 <4.0.0" sdk: ">=3.5.0 <4.0.0"