初始化提交

This commit is contained in:
2025-09-23 16:23:15 +08:00
commit 877b18a70f
590 changed files with 53617 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
import 'package:get/get.dart';
import '../controllers/kr_invite_controller.dart';
class KRInviteBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<KRInviteController>(
() => KRInviteController(),
);
}
}
@@ -0,0 +1,306 @@
import 'package:get/get.dart';
import 'package:kaer_with_panels/app/common/app_config.dart';
import 'package:kaer_with_panels/app/common/app_run_data.dart';
import 'package:kaer_with_panels/app/services/api_service/kr_api.user.dart';
import 'package:kaer_with_panels/app/utils/kr_common_util.dart';
import 'package:kaer_with_panels/app/localization/app_translations.dart';
import 'package:kaer_with_panels/app/routes/app_pages.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart';
import 'package:kaer_with_panels/app/modules/kr_main/controllers/kr_main_controller.dart';
import 'package:easy_refresh/easy_refresh.dart';
/// 邀请进度状态
class KRInviteProgress {
final int pending;
final int processing;
final int success;
final int expired;
final int registers;
final int totalCommission;
KRInviteProgress({
this.pending = 0,
this.processing = 0,
this.success = 0,
this.expired = 0,
this.registers = 0,
this.totalCommission = 0,
});
}
class KRInviteController extends GetxController {
final kr_progress = KRInviteProgress(
pending: 0,
processing: 0,
success: 0,
expired: 0,
registers: 0,
totalCommission: 0,
).obs;
final kr_referCode = ''.obs;
final kr_isLoading = false.obs;
final count = 0.obs;
final EasyRefreshController refreshController = EasyRefreshController();
@override
void onInit() {
super.onInit();
ever(KRAppRunData.getInstance().kr_isLogin, (value) {
if (value) {
_kr_fetchUserInfo();
_kr_fetchAffiliateCount();
} else {
kr_progress.value = KRInviteProgress(
pending: 0,
processing: 0,
success: 0,
expired: 0,
registers: 0,
totalCommission: 0,
);
kr_referCode.value = '';
}
});
if (KRAppRunData.getInstance().kr_isLogin.value) {
_kr_fetchUserInfo();
_kr_fetchAffiliateCount();
}
}
Future<void> _kr_fetchUserInfo() async {
try {
kr_isLoading.value = true;
final either = await KRUserApi().kr_getUserInfo();
either.fold(
(error) => KRCommonUtil.kr_showToast(error.msg),
(userInfo) {
kr_referCode.value = userInfo.referCode;
},
);
} catch (e) {
KRCommonUtil.kr_showToast(e.toString());
} finally {
kr_isLoading.value = false;
}
}
Future<bool> kr_checkLoginStatus() async {
return KRAppRunData.getInstance().kr_isLogin.value;
}
/// 获取分享链接
String kr_getShareLink() {
if (kr_referCode.isEmpty) {
return '';
}
return '${AppConfig.getInstance().kr_invitation_link}${kr_referCode.value}';
}
/// 获取二维码内容
String kr_getQRCodeContent() {
return kr_getShareLink();
}
/// 复制文本到剪贴板
Future<void> _kr_copyToClipboard(String text) async {
await Clipboard.setData(ClipboardData(text: text));
KRCommonUtil.kr_showToast(AppTranslations.kr_invite.copiedToClipboard);
}
Future<void> kr_handleQRShare() async {
if (!await kr_checkLoginStatus()) {
Get.find<KRMainController>().kr_setPage(0);
return;
}
if (kr_referCode.isEmpty) {
await _kr_fetchUserInfo();
if (kr_referCode.isEmpty) {
KRCommonUtil.kr_showToast(AppTranslations.kr_invite.getInviteCodeFailed);
return;
}
}
final qrContent = kr_getQRCodeContent();
if (qrContent.isEmpty) {
KRCommonUtil.kr_showToast(AppTranslations.kr_invite.generateQRCodeFailed);
return;
}
// 只有在登录状态下才弹出二维码对话框
if (KRAppRunData.getInstance().kr_isLogin.value) {
Get.dialog(
Dialog(
backgroundColor: Theme.of(Get.context!).cardColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.r),
),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 24.w),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
AppTranslations.kr_invite.shareQR,
style: KrAppTextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: Theme.of(Get.context!).textTheme.titleMedium?.color,
),
),
SizedBox(height: 16.w),
Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.r),
border: Border.all(
color: Theme.of(Get.context!).dividerColor.withOpacity(0.1),
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: Offset(0, 2),
),
],
),
child: QrImageView(
data: qrContent,
version: QrVersions.auto,
size: 200.w,
backgroundColor: Colors.white,
foregroundColor: Colors.black,
),
),
SizedBox(height: 20.w),
Container(
width: double.infinity,
height: 44.w,
child: TextButton(
onPressed: () => Get.back(),
style: TextButton.styleFrom(
backgroundColor: Theme.of(Get.context!).primaryColor.withOpacity(0.1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(22.r),
),
),
child: Text(
AppTranslations.kr_invite.close,
style: TextStyle(
color: Theme.of(Get.context!).textTheme.bodyMedium?.color,
fontSize: 16.sp,
fontWeight: FontWeight.w500,
fontFamily: 'AlibabaPuHuiTi-Regular',
),
),
),
),
],
),
),
),
);
}
}
void kr_viewRewardDetails() {
// TODO: 实现查看奖励明细功能
}
@override
void onReady() {
super.onReady();
}
@override
void onClose() {
refreshController.dispose();
super.onClose();
}
void increment() => count.value++;
/// 处理链接分享
Future<void> kr_handleLinkShare() async {
if (!await kr_checkLoginStatus()) {
Get.find<KRMainController>().kr_setPage(0);
return;
}
if (kr_referCode.isEmpty) {
await _kr_fetchUserInfo();
if (kr_referCode.isEmpty) {
KRCommonUtil.kr_showToast(AppTranslations.kr_invite.getInviteCodeFailed);
return;
}
}
final shareLink = kr_getShareLink();
if (shareLink.isEmpty) {
KRCommonUtil.kr_showToast(AppTranslations.kr_invite.generateShareLinkFailed);
return;
}
await _kr_copyToClipboard(shareLink);
}
/// 处理复制邀请码
Future<void> kr_handleCopyInviteCode() async {
if (!await kr_checkLoginStatus()) {
Get.find<KRMainController>().kr_setPage(0);
return;
}
if (kr_referCode.isEmpty) {
await _kr_fetchUserInfo();
if (kr_referCode.isEmpty) {
KRCommonUtil.kr_showToast(AppTranslations.kr_invite.getInviteCodeFailed);
return;
}
}
await _kr_copyToClipboard(kr_referCode.value);
}
/// 获取邀请统计信息
Future<void> _kr_fetchAffiliateCount() async {
try {
final either = await KRUserApi().kr_getAffiliateCount();
either.fold(
(error) => KRCommonUtil.kr_showToast(error.msg),
(affiliateCount) {
kr_progress.value = KRInviteProgress(
pending: kr_progress.value.pending,
processing: kr_progress.value.processing,
success: kr_progress.value.success,
expired: kr_progress.value.expired,
registers: affiliateCount.registers,
totalCommission: affiliateCount.totalCommission,
);
},
);
} catch (e) {
KRCommonUtil.kr_showToast(e.toString());
}
}
Future<void> kr_onRefresh() async {
if (!KRAppRunData.getInstance().kr_isLogin.value) {
refreshController.finishRefresh();
return;
}
try {
await _kr_fetchUserInfo();
await _kr_fetchAffiliateCount();
} finally {
refreshController.finishRefresh();
}
}
}
+450
View File
@@ -0,0 +1,450 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:kaer_with_panels/app/common/app_config.dart';
import 'package:kaer_with_panels/app/localization/app_translations.dart';
import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart';
import 'package:kaer_with_panels/app/widgets/kr_local_image.dart';
import '../controllers/kr_invite_controller.dart';
import 'package:flutter/services.dart';
import 'package:kaer_with_panels/app/utils/kr_common_util.dart';
import 'package:easy_refresh/easy_refresh.dart';
class _KRSliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
final Widget child;
final double maxHeight;
final double minHeight;
_KRSliverPersistentHeaderDelegate({
required this.child,
required this.maxHeight,
required this.minHeight,
});
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return SizedBox.expand(child: child);
}
@override
double get maxExtent => maxHeight;
@override
double get minExtent => minHeight;
@override
bool shouldRebuild(_KRSliverPersistentHeaderDelegate oldDelegate) {
return maxHeight != oldDelegate.maxHeight ||
minHeight != oldDelegate.minHeight ||
child != oldDelegate.child;
}
}
class KRInviteView extends GetView<KRInviteController> {
const KRInviteView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).primaryColor,
body: EasyRefresh(
controller: controller.refreshController,
onRefresh: controller.kr_onRefresh,
header: DeliveryHeader(
triggerOffset: 50.0,
springRebound: true,
),
child: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
SliverAppBar(
expandedHeight: 150.w,
floating: false,
pinned: true,
stretch: true,
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
flexibleSpace: FlexibleSpaceBar(
background: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.blue,
Colors.blue.shade400,
Colors.blue.shade200,
Theme.of(context).primaryColor,
],
stops: const [0.0, 0.3, 0.7, 1.0],
),
),
),
Positioned(
bottom: -50.w,
child: KrLocalImage(
imageName: "invite_top_bg",
width: 344.w,
height: 233.w,
fit: BoxFit.contain,
imageType: ImageType.png,
),
),
Positioned(
top: MediaQuery.of(context).padding.top + 16.w,
left: 16.w,
child: Text(
AppTranslations.kr_invite.title,
style: KrAppTextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
),
SliverPersistentHeader(
delegate: _KRSliverPersistentHeaderDelegate(
maxHeight: 120.w,
minHeight: 120.w,
child: Container(
color: Theme.of(context).primaryColor,
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: _kr_buildProgressCard(context),
),
),
pinned: true,
),
SliverToBoxAdapter(
child: SingleChildScrollView(
child: Container(
color: Theme.of(context).primaryColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_kr_buildInviteSteps(context),
_kr_buildShareButtons(context),
_kr_buildInviteRules(context),
SizedBox(height: 20.w),
],
),
),
),
),
],
),
),
);
}
Widget _kr_buildProgressCard(BuildContext context) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(12.w),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 8.w,
offset: Offset(0, 2.w),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppTranslations.kr_invite.inviteStats,
style: KrAppTextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.w),
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.1),
borderRadius: BorderRadius.circular(4.w),
),
child: Obx(() => Text(
controller.kr_progress.value.registers.toString(),
style: KrAppTextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: Colors.blue,
),
)),
),
],
),
SizedBox(height: 12.w),
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppTranslations.kr_invite.registers,
style: KrAppTextStyle(
fontSize: 13,
color: Theme.of(context).textTheme.bodySmall?.color,
),
),
SizedBox(height: 4.w),
Obx(() => Text(
controller.kr_progress.value.registers.toString(),
style: KrAppTextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
)),
],
),
),
SizedBox(width: 16.w),
Expanded(
child: Visibility(
visible: AppConfig().kr_is_daytime,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppTranslations.kr_invite.totalCommission,
style: KrAppTextStyle(
fontSize: 13,
color: Theme.of(context).textTheme.bodySmall?.color,
),
),
SizedBox(height: 4.w),
Text(
controller.kr_progress.value.totalCommission.toString(),
style: KrAppTextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: Colors.blue,
),
),
],
),
),
),
],
),
],
),
);
}
Widget _kr_buildInviteSteps(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(16.w, 32.w, 16.w, 16.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppTranslations.kr_invite.steps,
style: KrAppTextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
],
),
SizedBox(height: 16.w),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_kr_buildStepCard(context, Icons.person_add, AppTranslations.kr_invite.inviteFriend),
_kr_buildStepCard(context, Icons.mail, AppTranslations.kr_invite.acceptInvite),
_kr_buildStepCard(context, Icons.card_giftcard, AppTranslations.kr_invite.getReward),
],
),
],
),
);
}
Widget _kr_buildStepCard(BuildContext context, IconData icon, String text) {
return Container(
width: 100.w,
padding: EdgeInsets.all(12.r),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10.r,
offset: Offset(0, 2.w),
),
],
),
child: Column(
children: [
Container(
width: 48.r,
height: 48.r,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(icon, color: Colors.blue, size: 24.r),
),
SizedBox(height: 8.w),
Text(
text,
textAlign: TextAlign.center,
style: KrAppTextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
],
),
);
}
Widget _kr_buildShareButtons(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.w),
child: Column(
children: [
Row(
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: controller.kr_handleLinkShare,
icon: Icon(Icons.link, size: 20.r, color: Colors.white),
label: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
AppTranslations.kr_invite.shareLink,
style: TextStyle(
fontSize: 14.sp,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2196F3),
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24.r),
),
),
),
),
SizedBox(width: 16.w),
Expanded(
child: ElevatedButton.icon(
onPressed: controller.kr_handleQRShare,
icon: Icon(Icons.qr_code, size: 20.r, color: Colors.white),
label: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
AppTranslations.kr_invite.shareQR,
style: TextStyle(
fontSize: 14.sp,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2196F3),
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24.r),
),
),
),
),
],
),
SizedBox(height: 16.w),
Obx(() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'${AppTranslations.kr_invite.myInviteCode}: ${controller.kr_referCode.value}',
style: KrAppTextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
IconButton(
icon: Icon(Icons.copy, size: 20.r, color: Colors.blue),
onPressed: () {
Clipboard.setData(ClipboardData(text: controller.kr_referCode.value));
KRCommonUtil.kr_showToast(
AppTranslations.kr_invite.inviteCodeCopied,
);
},
),
],
);
}),
],
),
);
}
Widget _kr_buildInviteRules(BuildContext context) {
return Padding(
padding: EdgeInsets.all(16.r),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppTranslations.kr_invite.rules,
style: KrAppTextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
SizedBox(height: 16.w),
Text(
AppTranslations.kr_invite.rule1,
style: KrAppTextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Theme.of(context).textTheme.bodySmall?.color,
),
),
SizedBox(height: 8.w),
Text(
AppTranslations.kr_invite.rule2,
style: KrAppTextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Theme.of(context).textTheme.bodySmall?.color,
),
),
],
),
);
}
}