add
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../services/invite_service.dart';
|
||||
|
||||
/// 邀请好友页:我的邀请码 + 推广统计 + 一键复制推广文案(含口令与下载链接)
|
||||
class InviteScreen extends StatefulWidget {
|
||||
const InviteScreen({super.key});
|
||||
|
||||
@override
|
||||
State<InviteScreen> createState() => _InviteScreenState();
|
||||
}
|
||||
|
||||
class _InviteScreenState extends State<InviteScreen> {
|
||||
late Future<ReferralInfo> _future;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_future = InviteService.fetchMyReferral();
|
||||
}
|
||||
|
||||
Future<void> _copyShareText(ReferralInfo info) async {
|
||||
final text = InviteService.buildShareText(
|
||||
inviteCode: info.inviteCode,
|
||||
inviteUrl: info.inviteUrl,
|
||||
);
|
||||
await Clipboard.setData(ClipboardData(text: text));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('推广文案已复制,快去分享给好友吧')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('邀请好友')),
|
||||
body: FutureBuilder<ReferralInfo>(
|
||||
future: _future,
|
||||
builder: (context, snap) {
|
||||
if (snap.hasError) {
|
||||
return Center(
|
||||
child: TextButton(
|
||||
onPressed: () => setState(() => _future = InviteService.fetchMyReferral()),
|
||||
child: const Text('加载失败,点击重试'),
|
||||
),
|
||||
);
|
||||
}
|
||||
final info = snap.data;
|
||||
if (info == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
children: [
|
||||
// 邀请码卡片
|
||||
Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [AppColors.primary, AppColors.secondary],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const Text('我的邀请码', style: TextStyle(color: Colors.white70, fontSize: 13)),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
info.inviteCode,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: 4,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () => _copyShareText(info),
|
||||
icon: const Icon(Icons.copy, size: 18),
|
||||
label: const Text('复制推广文案'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 推广统计
|
||||
Row(
|
||||
children: [
|
||||
_Stat(label: '累计邀请', value: '${info.totalInvitees}'),
|
||||
_Stat(label: '已激活', value: '${info.activatedCount}'),
|
||||
_Stat(label: '奖励积分', value: '${info.rewardPointsTotal}'),
|
||||
_Stat(label: '返利资产', value: info.rebateAssetsTotal.toStringAsFixed(1)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 规则说明
|
||||
const Text('邀请规则', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 12),
|
||||
const _Rule(text: '好友通过你的推广链接或口令注册,即绑定为你的下级'),
|
||||
const _Rule(text: '下级 72 小时内观看满 3 个视频即激活,你得邀请积分奖励'),
|
||||
const _Rule(text: '下级充值积分,你按比例的返利资产(可提现)'),
|
||||
if (!info.eligible) ...[
|
||||
const SizedBox(height: 8),
|
||||
const _Rule(text: '开通会员后才可享受邀请奖励资格', highlight: true),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Stat extends StatelessWidget {
|
||||
const _Stat({required this.label, required this.value});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(value, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 4),
|
||||
Text(label, style: const TextStyle(color: AppColors.textSecondary, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Rule extends StatelessWidget {
|
||||
const _Rule({required this.text, this.highlight = false});
|
||||
|
||||
final String text;
|
||||
final bool highlight;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('· ', style: TextStyle(color: highlight ? AppColors.gold : AppColors.textSecondary)),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: highlight ? AppColors.gold : AppColors.textSecondary,
|
||||
fontSize: 13,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user