// lib/app/modules/hi_menu/widgets/user_info_card.dart import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:kaer_with_panels/app/modules/hi_menu/controllers/hi_menu_controller.dart'; import 'package:kaer_with_panels/app/routes/app_pages.dart'; import 'package:kaer_with_panels/app/widgets/kr_local_image.dart'; /// 用户信息展示卡片 Widget /// /// 显示用户头像、ID和套餐到期时间,并提供点击跳转到套餐页面的功能。 class UserInfoCard extends StatelessWidget { const UserInfoCard({ super.key, required this.controller, required this.userId, }); final HIMenuController controller; final String userId; @override Widget build(BuildContext context) { return GestureDetector( onTap: () { // 点击后用户页面 Get.toNamed(Routes.HI_USER_INFO); }, // 让整个卡片的透明区域也能响应点击 behavior: HitTestBehavior.opaque, child: Container( padding: EdgeInsets.fromLTRB(7.w, 4, 18.w, 4), decoration: BoxDecoration( color: Colors.transparent, borderRadius: BorderRadius.circular(35.5.r), border: Border.all( color: Colors.white, width: 2.0, // 👇 核心改动: 将边框宽度设置为 2.0 ), ), child: Row( children: [ CircleAvatar( radius: 18.r, backgroundColor: Colors.white, child: KrLocalImage( imageName: 'hi-home-logo', imageType: ImageType.svg, width: 16.w, height: 16.h, ), ), SizedBox(width: 12.w), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'ID: $userId', style: TextStyle( color: Colors.white, fontSize: 14.sp, fontWeight: FontWeight.bold, ), ), Obx(() { final currentSubscribe = controller.kr_subscribeService.kr_currentSubscribe.value; String expiryText; if (currentSubscribe == null) { expiryText = '尚未购买套餐'; } else { final now = DateTime.now(); DateTime? expireDateTime; try { expireDateTime = DateTime.parse(currentSubscribe.expireTime); } catch (e) { expireDateTime = null; } if (expireDateTime == null) { expiryText = '套餐信息无效'; } else if (expireDateTime.isBefore(now)) { final formattedExpireDate = '${expireDateTime.year}/${expireDateTime.month.toString().padLeft(2, '0')}/${expireDateTime.day.toString().padLeft(2, '0')}'; expiryText = '已于 $formattedExpireDate 到期'; } else { final year = expireDateTime.year; final month = expireDateTime.month.toString().padLeft(2, '0'); final day = expireDateTime.day.toString().padLeft(2, '0'); final hour = expireDateTime.hour.toString().padLeft(2, '0'); final minute = expireDateTime.minute.toString().padLeft(2, '0'); final second = expireDateTime.second.toString().padLeft(2, '0'); // 2. 拼接成最终的字符串 final formattedDateTime = '$year/$month/$day $hour:$minute:$second'; expiryText = '到期时间:$formattedDateTime'; } } return Text( expiryText, style: TextStyle( color: Colors.white, fontSize: 12.sp, ), ); }), ], ), ), SizedBox(width: 8.w), const KrLocalImage( imageName: 'arrow-right-icon', imageType: ImageType.svg, color: Colors.white, ), ], ), ), ); } }