feat: 完成智能电网电工端 Flutter 应用初始化

创建完整的 Flutter 项目结构,包含 Android 和 iOS 平台配置、核心网络层、路由、状态管理及业务模块(订单、收益、认证),适配原 uni-app 项目功能逻辑
This commit is contained in:
andyesfly committed 2026-10-06 11:54:10 +08:00
commit 56830e94ec
108 files changed
+9272

No files matched your search

@@ -0,0 +1,425 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../core/network/api_response.dart';
import '../../../core/providers.dart';
import '../../../core/theme/app_colors.dart';
import '../../../core/theme/app_dimens.dart';
import '../../../core/theme/app_typography.dart';
import '../../../shared/widgets/app_feedback.dart';
import '../../../shared/widgets/x_card.dart';
import '../../../shared/widgets/x_common.dart';
import '../../../shared/widgets/x_icon.dart';
import '../../../shared/widgets/x_top_bar.dart';
import '../../auth/application/session_controller.dart';
import '../../auth/data/auth_models.dart';
/// 渐变卡内各级白色透明度,对应源 `rgba(255,255,255,x)`。
const _white80 = Color(0xCCFFFFFF);
const _white60 = Color(0x99FFFFFF);
const _white20 = Color(0x33FFFFFF);
const _white15 = Color(0x26FFFFFF);
const _white10 = Color(0x1AFFFFFF);
/// 个人资料接口。后端未提供独立 provider,故在此局部声明。
/// 源页面「我的」只展示一张证书,这里取 `WorkerProfile.primaryCert`。
final _profileProvider = FutureProvider.autoDispose<WorkerProfile>((ref) async {
final res = await ref.watch(authApiProvider).profile();
if (!res.isOk || res.data == null) throw ApiException(res.message);
return res.data!;
});
/// 「我的」Tab,逐像素复刻源 `src/pages/profile/index.vue`。
///
/// 顶栏由本页渲染;底部 Tab 栏由 `TabsPage` 提供。
/// 「专业技能」区块与「从业年限」统计项后端无对应字段,已按约定省略。
class ProfileTab extends ConsumerWidget {
const ProfileTab({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final session = ref.watch(sessionProvider);
final profileAsync = ref.watch(_profileProvider);
final unread = ref.watch(noticeUnreadCountProvider);
final profile = profileAsync.value;
final worker = profile?.basic ?? session.worker;
return XPageShell(
topBar: XTopBar.brand(
height: 56,
logoSize: 28,
titleSize: 18,
titleWeight: FontWeight.w600,
trailingBadge: unread,
onTrailingTap: () => context.push('/notice'),
),
child: worker == null
? _placeholder(profileAsync)
: ListView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.only(bottom: 96),
children: [
const Padding(
padding: EdgeInsets.fromLTRB(16, 24, 16, 24),
child: XPageTitle(
title: '我的',
subtitle: '管理您的个人资料与账户设置',
),
),
_profileCard(worker, profile?.primaryCert),
_menuSection(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: _logoutButton(ref),
),
],
),
);
}
/// 无缓存资料时展示加载 / 错误态。
Widget _placeholder(AsyncValue<WorkerProfile> async) {
final text = async.when(
loading: () => '加载中...',
error: (error, _) => error.toString(),
data: (_) => '加载中...',
);
return ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: [XPlaceholder(text: text)],
);
}
/// 资料卡:渐变底 + 头像 + 姓名 / ID + 证书区 + 两项统计。
Widget _profileCard(WorkerInfo worker, CertInfo? cert) {
final certType = cert?.certType ?? '';
final certTitle = certType.isEmpty ? '电工职业资格证' : certType;
return Container(
margin: const EdgeInsets.fromLTRB(16, 0, 16, 24),
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.primaryDeep, AppColors.primary],
),
borderRadius: BorderRadius.circular(AppRadius.xl),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
SizedBox(
width: 64,
height: 64,
child: Stack(
children: [
Container(
width: 64,
height: 64,
alignment: Alignment.center,
decoration: const BoxDecoration(
color: AppColors.onPrimary,
shape: BoxShape.circle,
),
child: Text(
worker.avatarText,
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.w700,
color: AppColors.primary,
),
),
),
Positioned(
right: 2,
bottom: 2,
child: Container(
width: 16,
height: 16,
decoration: BoxDecoration(
color: AppColors.success,
shape: BoxShape.circle,
border: Border.all(
color: AppColors.primary,
width: 2,
),
),
),
),
],
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
worker.displayName,
style: AppTypography.titleLg.copyWith(
color: AppColors.onPrimary,
letterSpacing: -0.44,
),
),
const SizedBox(height: 4),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 4,
),
decoration: BoxDecoration(
color: _white20,
borderRadius: BorderRadius.circular(AppRadius.regular),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'ID',
style: TextStyle(
fontSize: 11,
color: _white80,
fontWeight: FontWeight.w600,
),
),
const SizedBox(width: 6),
Text(
'${worker.id}',
style: const TextStyle(
fontSize: 13,
color: AppColors.onPrimary,
fontWeight: FontWeight.w500,
),
),
],
),
),
],
),
),
],
),
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: _white15,
borderRadius: BorderRadius.circular(AppRadius.lg),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const XIcon('cert', size: 18, color: AppColors.onPrimary),
const SizedBox(width: 8),
Expanded(
child: Text(
certTitle,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: AppColors.onPrimary,
),
),
),
_certBadge(worker),
],
),
const SizedBox(height: 12),
if (cert == null)
const Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: Text(
'暂无资质证照',
style: TextStyle(fontSize: 13, color: _white60),
),
)
else ...[
_certRow('证书编号', cert.certNo),
_certRow('有效期至', cert.expireDate, divider: false),
],
],
),
),
const SizedBox(height: 20),
Row(
children: [
Expanded(child: _statItem('${worker.completedCount}', '已完成订单')),
Container(width: 1, height: 40, color: _white20),
Expanded(
child: _statItem(worker.rating.toStringAsFixed(1), '评分'),
),
],
),
],
),
);
}
/// 审核通过显示绿色「已认证」,否则以弱化样式显示审核状态文案。
Widget _certBadge(WorkerInfo worker) {
final approved = worker.isApproved;
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: approved ? AppColors.success : _white20,
borderRadius: BorderRadius.circular(6),
),
child: Text(
approved ? '已认证' : worker.auditStatusText,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: approved ? AppColors.onPrimary : _white80,
),
),
);
}
Widget _certRow(String label, String value, {bool divider = true}) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
border: divider ? const Border(bottom: BorderSide(color: _white10)) : null,
),
child: Row(
children: [
Text(label, style: const TextStyle(fontSize: 13, color: _white80)),
const SizedBox(width: 12),
Expanded(
child: Text(
value,
textAlign: TextAlign.right,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: AppColors.onPrimary,
),
),
),
],
),
);
}
Widget _statItem(String value, String label) => Column(
children: [
Text(
value,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.w700,
color: AppColors.onPrimary,
letterSpacing: -0.48,
),
),
const SizedBox(height: 4),
Text(label, style: const TextStyle(fontSize: 12, color: _white80)),
],
);
/// 两组 `ios-card` 菜单,行点击仅提示(同源实现)。
Widget _menuSection() {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
child: Column(
children: [
_menuGroup(const [
('order', '我的订单'),
('earnings', '收益记录'),
('notify', '账户设置'),
]),
const SizedBox(height: 12),
_menuGroup(const [('star', '帮助中心'), ('shandian', '关于我们')]),
],
),
);
}
Widget _menuGroup(List<(String, String)> items) {
return XCard(
radius: AppRadius.lg,
padding: const EdgeInsets.symmetric(vertical: 4),
child: Column(
children: [
for (var i = 0; i < items.length; i++) ...[
if (i > 0)
Container(
height: 1,
margin: const EdgeInsets.symmetric(horizontal: 16),
color: AppColors.borderSoft,
),
_menuRow(items[i].$1, items[i].$2),
],
],
),
);
}
Widget _menuRow(String icon, String label) {
return GestureDetector(
onTap: () => showAppToast(label),
behavior: HitTestBehavior.opaque,
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
XIcon(icon, size: 22, color: AppColors.onSurfaceVariant),
const SizedBox(width: 12),
Expanded(
child: Text(
label,
style: AppTypography.bodyLg.copyWith(
color: AppColors.onSurface,
),
),
),
const XIcon(
'arrow-right',
size: 16,
color: AppColors.textPlaceholder,
),
],
),
),
);
}
Widget _logoutButton(WidgetRef ref) {
return XCard(
radius: AppRadius.lg,
padding: EdgeInsets.zero,
onTap: () => _handleLogout(ref),
child: const SizedBox(
height: 48,
width: double.infinity,
child: Center(
child: Text(
'退出登录',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: AppColors.tertiaryContainer,
),
),
),
),
);
}
Future<void> _handleLogout(WidgetRef ref) async {
final confirmed = await showAppConfirm(
title: '提示',
content: '确定要退出登录吗?',
confirmText: '确定',
cancelText: '取消',
);
if (!confirmed) return;
await ref.read(sessionProvider.notifier).logout();
}
}