feat: 二级页面色彩刷新 + 用药/通知/设备重构 + 后端健康档案/通知管线增强 + 大量测试

## 后端
- 健康档案: 新增手术状态字段 + EF 迁移; HealthArchiveService 新增查询方法
- 健康记录: HealthRecordService 新增批量/统计方法; 契约扩展
- 用药: 新增 MedicationScheduleStatus 枚举; MedicationService 排班逻辑调整
- 通知: EfUserNotificationPipeline 重构; 新增 EfReminderCatchUpService; 通知管线支持更多场景
- 用户: UserService 账号删除逻辑; 新增 local_account_file_cleanup; EfUserRepository 扩展
- AI: medication_agent_handler 微调; prompt_manager 优化; AiConversationService 上下文处理
- Endpoint: doctor/medication/exercise/health/notification/user 等多接口调整
- BackgroundService: health_record_reminder_service 重构, 提醒补漏逻辑
- 测试: 新增 account_deletion/doctor_endpoint/medication_schedule/medication_update/prompt_manager 测试

## 前端
- UI 系统: app_theme 大幅重构; app_colors/app_design_tokens/app_module_visuals 调整; 二级页面色彩刷新
- 主页: home_page 背景渐变 + 消息列表提取 _HomeMessages + 通知检查逻辑; chat_messages_view 全面重构
- 用药: medication_list/edit/checkin 三页重构, 新增 medication_ui_logic 抽取
- 通知: notification_prefs_page 重构, 新增 notification_prefs_logic; notification_center 优化
- 设备: device_management 重构, 新增 device_sync_ui_logic; device_scan 优化
- 趋势图: trend_page 大幅重构
- 登录: login_page 重构
- 个人资料: 新增 profile_edit_page; profile_page 优化
- 运动: 新增 exercise/ 目录 + care_plan_ui_logic
- 其他: remaining_pages/report_pages/health_drawer/admin/doctor 等多页面调整
- 组件: common_widgets/app_empty_state/app_error_state/app_future_view/app_toast/ai_content 优化
- Provider: chat_provider/consultation_provider/data_providers/auth_provider 调整
- AndroidManifest: 移除多余权限
- 测试: 新增 ai_content/care_plan/home_message/login_flow/medication_checkin/medication_ui/notification_prefs/profile_device/secondary_page/swipe_delete 等大量测试

## 文档
- 新增 ui-design-system.md 设计系统文档
- 新增 secondary-page-color-refresh 计划 + specs 目录
This commit is contained in:
MingNian
2026-07-15 23:22:52 +08:00
parent e654c1e0cc
commit fade61ac21
138 changed files with 12636 additions and 5013 deletions

View File

@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import '../../core/api_client.dart';
import '../../core/app_colors.dart';
import '../../core/app_design_tokens.dart';
import '../../core/app_module_visuals.dart';
import '../../core/app_theme.dart';
import '../../core/navigation_provider.dart';
@@ -22,9 +25,6 @@ class MedicationCheckInPage extends ConsumerStatefulWidget {
}
class _MedicationCheckInPageState extends ConsumerState<MedicationCheckInPage> {
static const _visual = AppModuleVisuals.medication;
static const _softGreen = Color(0xFFEAF8EF);
Future<List<Map<String, dynamic>>>? _future;
final Set<String> _busyDoses = {};
@@ -34,11 +34,9 @@ class _MedicationCheckInPageState extends ConsumerState<MedicationCheckInPage> {
_load();
}
void _load() {
setState(() {
_future = ref.read(medicationReminderProvider.future);
});
}
void _load() => setState(() {
_future = ref.read(medicationReminderProvider.future);
});
Future<void> _refresh() async {
ref.invalidate(medicationReminderProvider);
@@ -48,26 +46,32 @@ class _MedicationCheckInPageState extends ConsumerState<MedicationCheckInPage> {
Future<void> _toggleDose(String medId, String time, bool taken) async {
final doseKey = '$medId-$time';
if (_busyDoses.contains(doseKey)) return;
if (medId.isEmpty || time.isEmpty || _busyDoses.contains(doseKey)) return;
setState(() => _busyDoses.add(doseKey));
try {
final api = ref.read(apiClientProvider);
if (taken) {
await api.delete('/api/medications/$medId/confirm-dose/$time');
} else {
await api.post(
final response = await api.post(
'/api/medications/$medId/confirm-dose',
data: {'scheduledTime': time, 'status': 'taken'},
);
final data = response.data is Map ? response.data['data'] : null;
if (data is Map && data['success'] == false) {
throw const ApiException('该次服药已经打卡');
}
}
ref.invalidate(medicationReminderProvider);
ref.invalidate(medicationListProvider);
_load();
} catch (e) {
debugPrint('[MedCheckIn] 打卡失败: $e');
} catch (error) {
if (mounted) {
AppToast.show(context, '打卡失败,请稍后重试', type: AppToastType.error);
AppToast.show(
context,
error is ApiException ? error.message : '打卡失败,请稍后重试',
type: AppToastType.error,
);
}
} finally {
if (mounted) setState(() => _busyDoses.remove(doseKey));
@@ -83,59 +87,86 @@ class _MedicationCheckInPageState extends ConsumerState<MedicationCheckInPage> {
onPressed: () => popRoute(ref),
),
title: const Text('服药打卡'),
centerTitle: true,
),
body: FutureBuilder<List<Map<String, dynamic>>>(
future: _future,
builder: (ctx, snap) {
if (snap.connectionState == ConnectionState.waiting &&
!snap.hasData) {
return const Center(
child: CircularProgressIndicator(color: AppTheme.primary),
);
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting &&
!snapshot.hasData) {
return const Center(child: CircularProgressIndicator());
}
if (snap.hasError) {
if (snapshot.hasError) {
return AppErrorState(title: '用药信息加载失败', onRetry: _load);
}
final reminders = _filterReminders(snap.data ?? []);
final reminders = _filterReminders(snapshot.data ?? const []);
if (reminders.isEmpty) {
return RefreshIndicator(
onRefresh: _refresh,
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: const [
SizedBox(height: 92),
children: [
const SizedBox(height: 92),
AppEmptyState(
icon: Icons.task_alt_outlined,
title: '今天的用药已完成',
subtitle: '下拉可刷新最新用药提醒',
icon: AppModuleVisuals.medication.icon,
title: '今天没有服药安排',
subtitle: '今日可以安心休息,下拉可刷新最新计划',
iconColor: AppColors.medication,
),
],
),
);
}
final grouped = _groupByMedication(reminders);
final total = reminders.length;
final taken = reminders.where(_isTaken).length;
final pending = total - taken;
final sorted = [...reminders]
..sort(
(a, b) => _formatTime(
a['scheduledTime']?.toString() ?? '',
).compareTo(_formatTime(b['scheduledTime']?.toString() ?? '')),
);
final taken = sorted.where(_isTaken).length;
return RefreshIndicator(
onRefresh: _refresh,
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
padding: AppSpacing.page,
children: [
_CheckInSummary(total: total, taken: taken, pending: pending),
const SizedBox(height: 14),
...grouped.entries.map(
(entry) => _MedicationDoseCard(
name: entry.key,
doses: entry.value,
busyDoses: _busyDoses,
onToggle: _toggleDose,
_DoseProgressHeader(total: sorted.length, taken: taken),
const SizedBox(height: 18),
Container(
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: AppRadius.lgBorder,
),
child: Column(
children: List.generate(sorted.length, (index) {
final dose = sorted[index];
final key =
'${dose['id']?.toString() ?? ''}-${dose['scheduledTime']?.toString() ?? ''}';
return _DoseTimelineRow(
dose: dose,
isFirst: index == 0,
isLast: index == sorted.length - 1,
isBusy: _busyDoses.contains(key),
onToggle: _toggleDose,
);
}),
),
),
const SizedBox(height: 18),
const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
LucideIcons.shield,
size: 16,
color: AppColors.textHint,
),
SizedBox(width: 6),
Text(
'请按医嘱服药,如有不适及时咨询医生',
style: TextStyle(fontSize: 12, color: AppColors.textHint),
),
],
),
],
),
@@ -148,210 +179,88 @@ class _MedicationCheckInPageState extends ConsumerState<MedicationCheckInPage> {
List<Map<String, dynamic>> _filterReminders(
List<Map<String, dynamic>> reminders,
) {
if (widget.medId == null) return reminders;
return reminders.where((r) => r['id']?.toString() == widget.medId).toList();
}
Map<String, List<Map<String, dynamic>>> _groupByMedication(
List<Map<String, dynamic>> reminders,
) {
final grouped = <String, List<Map<String, dynamic>>>{};
for (final reminder in reminders) {
final name = reminder['name']?.toString().trim();
grouped
.putIfAbsent(name?.isNotEmpty == true ? name! : '未命名药品', () {
return <Map<String, dynamic>>[];
})
.add(reminder);
}
for (final doses in grouped.values) {
doses.sort(
(a, b) => _formatTime(
a['scheduledTime']?.toString() ?? '',
).compareTo(_formatTime(b['scheduledTime']?.toString() ?? '')),
);
}
return grouped;
if (widget.medId == null || widget.medId!.isEmpty) return reminders;
return reminders
.where((item) => item['id']?.toString() == widget.medId)
.toList();
}
}
class _CheckInSummary extends StatelessWidget {
Map<String, List<Map<String, dynamic>>> groupMedicationReminders(
List<Map<String, dynamic>> reminders,
) {
final grouped = <String, List<Map<String, dynamic>>>{};
for (var index = 0; index < reminders.length; index++) {
final reminder = reminders[index];
final medicationId = reminder['id']?.toString().trim();
final key = medicationId?.isNotEmpty == true
? medicationId!
: 'unknown-$index';
grouped.putIfAbsent(key, () => <Map<String, dynamic>>[]).add(reminder);
}
for (final doses in grouped.values) {
doses.sort(
(a, b) => _formatTime(
a['scheduledTime']?.toString() ?? '',
).compareTo(_formatTime(b['scheduledTime']?.toString() ?? '')),
);
}
return grouped;
}
class _DoseProgressHeader extends StatelessWidget {
final int total;
final int taken;
final int pending;
const _CheckInSummary({
required this.total,
required this.taken,
required this.pending,
});
const _DoseProgressHeader({required this.total, required this.taken});
@override
Widget build(BuildContext context) {
final now = DateTime.now();
final progress = total == 0 ? 0.0 : taken / total;
return Container(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.fromLTRB(16, 16, 16, 15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppColors.border, width: 1.1),
boxShadow: [AppTheme.shadowLight],
borderRadius: AppRadius.lgBorder,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 42,
height: 42,
decoration: BoxDecoration(
gradient: _MedicationCheckInPageState._visual.gradient,
borderRadius: BorderRadius.circular(14),
),
child: const Icon(
Icons.medication_outlined,
color: Colors.white,
size: 24,
),
),
const SizedBox(width: 12),
const Expanded(
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'今日服药进度',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
),
'${now.month}${now.day}日 · 今日用药',
style: AppTextStyles.sectionTitle,
),
SizedBox(height: 2),
const SizedBox(height: 3),
Text(
'按提醒时间逐项确认,保持用药节奏',
style: TextStyle(
fontSize: 13,
color: AppColors.textSecondary,
),
'$taken / $total 已完成',
style: AppTextStyles.listSubtitle,
),
],
),
),
Text(
'${(progress * 100).round()}%',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w900,
color: _MedicationCheckInPageState._visual.color,
style: AppTextStyles.summaryTitle.copyWith(
color: AppColors.medication,
),
),
],
),
const SizedBox(height: 16),
const SizedBox(height: 12),
ClipRRect(
borderRadius: BorderRadius.circular(999),
borderRadius: AppRadius.pillBorder,
child: LinearProgressIndicator(
minHeight: 9,
minHeight: 5,
value: progress,
backgroundColor: AppColors.cardInner,
valueColor: AlwaysStoppedAnimation<Color>(
_MedicationCheckInPageState._visual.color,
),
),
),
const SizedBox(height: 14),
Row(
children: [
Expanded(
child: _SummaryStat(
label: '待完成',
value: '$pending',
icon: Icons.schedule_outlined,
color: AppColors.warning,
),
),
const SizedBox(width: 8),
Expanded(
child: _SummaryStat(
label: '已打卡',
value: '$taken',
icon: Icons.check_circle_outline,
color: AppTheme.success,
),
),
const SizedBox(width: 8),
Expanded(
child: _SummaryStat(
label: '总次数',
value: '$total',
icon: Icons.format_list_numbered_outlined,
color: _MedicationCheckInPageState._visual.color,
),
),
],
),
],
),
);
}
}
class _SummaryStat extends StatelessWidget {
final String label;
final String value;
final IconData icon;
final Color color;
const _SummaryStat({
required this.label,
required this.value,
required this.icon,
required this.color,
});
@override
Widget build(BuildContext context) {
return Container(
constraints: const BoxConstraints(minHeight: 58),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 9),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: color.withValues(alpha: 0.14)),
),
child: Row(
children: [
Icon(icon, color: color, size: 17),
const SizedBox(width: 7),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
),
),
Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.w700,
color: AppColors.textSecondary,
),
),
],
valueColor: const AlwaysStoppedAnimation(AppColors.medication),
),
),
],
@@ -360,138 +269,16 @@ class _SummaryStat extends StatelessWidget {
}
}
class _MedicationDoseCard extends StatelessWidget {
final String name;
final List<Map<String, dynamic>> doses;
final Set<String> busyDoses;
final Future<void> Function(String medId, String time, bool taken) onToggle;
const _MedicationDoseCard({
required this.name,
required this.doses,
required this.busyDoses,
required this.onToggle,
});
@override
Widget build(BuildContext context) {
final dosage = doses.first['dosage']?.toString().trim() ?? '';
final takenCount = doses.where(_isTaken).length;
final allTaken = takenCount == doses.length;
return Container(
margin: const EdgeInsets.only(bottom: 12),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: allTaken
? AppTheme.success.withValues(alpha: 0.26)
: AppColors.border,
width: 1.1,
),
boxShadow: [AppTheme.shadowLight],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: allTaken
? _MedicationCheckInPageState._softGreen
: _MedicationCheckInPageState._visual.lightColor,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: AppColors.borderLight),
),
child: Icon(
allTaken ? Icons.done_all_rounded : Icons.medication_liquid,
color: allTaken
? AppTheme.success
: _MedicationCheckInPageState._visual.color,
size: 24,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
),
),
if (dosage.isNotEmpty) ...[
const SizedBox(height: 2),
Text(
dosage,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 14,
color: AppColors.textSecondary,
),
),
],
],
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 5),
decoration: BoxDecoration(
color: allTaken
? _MedicationCheckInPageState._softGreen
: AppColors.cardInner,
borderRadius: BorderRadius.circular(999),
),
child: Text(
'$takenCount/${doses.length}',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w800,
color: allTaken
? AppTheme.success
: AppColors.textSecondary,
),
),
),
],
),
const SizedBox(height: 14),
for (var i = 0; i < doses.length; i++) ...[
_DoseRow(
dose: doses[i],
isLast: i == doses.length - 1,
isBusy: busyDoses.contains(
'${doses[i]['id']?.toString() ?? ''}-${doses[i]['scheduledTime']?.toString() ?? ''}',
),
onToggle: onToggle,
),
],
],
),
);
}
}
class _DoseRow extends StatelessWidget {
class _DoseTimelineRow extends StatelessWidget {
final Map<String, dynamic> dose;
final bool isFirst;
final bool isLast;
final bool isBusy;
final Future<void> Function(String medId, String time, bool taken) onToggle;
final Future<void> Function(String, String, bool) onToggle;
const _DoseRow({
const _DoseTimelineRow({
required this.dose,
required this.isFirst,
required this.isLast,
required this.isBusy,
required this.onToggle,
@@ -499,171 +286,175 @@ class _DoseRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
final time = dose['scheduledTime']?.toString() ?? '';
final medId = dose['id']?.toString() ?? '';
final isTaken = _isTaken(dose);
final displayTime = _formatTime(time);
final statusColor = isTaken ? AppTheme.success : AppColors.warning;
final rawTime = dose['scheduledTime']?.toString() ?? '';
final time = _formatTime(rawTime);
final name = dose['name']?.toString().trim().isNotEmpty == true
? dose['name'].toString().trim()
: '未命名药品';
final dosage = dose['dosage']?.toString().trim() ?? '';
final status = dose['status']?.toString().toLowerCase() ?? 'scheduled';
final taken = status == 'taken';
final scheduled = status == 'scheduled';
final color = _statusColor(status);
return IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
return ConstrainedBox(
constraints: const BoxConstraints(minHeight: 92),
child: Stack(
children: [
SizedBox(
width: 28,
child: Column(
Padding(
padding: const EdgeInsets.symmetric(horizontal: 14),
child: Row(
children: [
Container(
width: 22,
height: 22,
decoration: BoxDecoration(
color: isTaken ? AppTheme.success : Colors.white,
shape: BoxShape.circle,
border: Border.all(
color: isTaken ? AppTheme.success : AppColors.border,
width: 2,
),
SizedBox(
width: 54,
child: Text(
time,
style: AppTextStyles.listTitle.copyWith(fontSize: 18),
),
child: isTaken
? const Icon(Icons.check, size: 14, color: Colors.white)
: null,
),
if (!isLast)
Expanded(
child: Container(
width: 2,
margin: const EdgeInsets.symmetric(vertical: 4),
color: isTaken
? AppTheme.success.withValues(alpha: 0.34)
: AppColors.borderLight,
),
SizedBox(
width: 28,
height: 92,
child: Stack(
alignment: Alignment.center,
children: [
if (!isFirst)
Positioned(
top: 0,
bottom: 46,
child: Container(width: 2, color: AppColors.divider),
),
if (!isLast)
Positioned(
top: 46,
bottom: 0,
child: Container(width: 2, color: AppColors.divider),
),
Container(
width: 20,
height: 20,
decoration: BoxDecoration(
color: taken ? color : Colors.white,
shape: BoxShape.circle,
border: Border.all(color: color, width: 2),
),
child: taken
? const Icon(
Icons.check,
size: 13,
color: Colors.white,
)
: null,
),
],
),
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppTextStyles.listTitle.copyWith(fontSize: 16),
),
const SizedBox(height: 3),
Text(
[
dosage,
_statusLabel(status),
].where((text) => text.isNotEmpty).join(' · '),
style: AppTextStyles.listSubtitle.copyWith(
fontSize: 13,
color: color,
),
),
],
),
),
const SizedBox(width: 8),
SizedBox(
height: 36,
child: OutlinedButton(
onPressed: isBusy || scheduled
? null
: () => onToggle(medId, rawTime, taken),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 13),
backgroundColor: taken
? AppColors.successLight
: Colors.white,
foregroundColor: taken
? AppColors.successText
: AppColors.medication,
disabledForegroundColor: AppColors.textHint,
side: BorderSide(
color: scheduled
? AppColors.borderLight
: (taken
? AppColors.successText
: AppColors.medication),
),
shape: RoundedRectangleBorder(
borderRadius: AppRadius.smBorder,
),
),
child: isBusy
? const SizedBox(
width: 14,
height: 14,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Text(
scheduled ? '未到时间' : (taken ? '撤销' : '打卡'),
style: AppTextStyles.miniButton,
),
),
),
],
),
),
const SizedBox(width: 10),
Expanded(
child: Padding(
padding: EdgeInsets.only(bottom: isLast ? 0 : 12),
child: Container(
padding: const EdgeInsets.fromLTRB(12, 10, 10, 10),
decoration: BoxDecoration(
color: isTaken
? _MedicationCheckInPageState._softGreen
: const Color(0xFFF8FAFC),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isTaken
? AppTheme.success.withValues(alpha: 0.18)
: AppColors.borderLight,
),
),
child: Row(
children: [
Icon(Icons.access_time, size: 18, color: statusColor),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
displayTime,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: isTaken ? AppTheme.textSub : AppTheme.text,
),
),
const SizedBox(height: 1),
Text(
isTaken ? '已完成打卡' : '等待确认服用',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: isTaken
? AppTheme.success
: AppColors.textSecondary,
),
),
],
),
),
const SizedBox(width: 8),
SizedBox(
height: 36,
child: FilledButton.icon(
onPressed: isBusy || medId.isEmpty || time.isEmpty
? null
: () => onToggle(medId, time, isTaken),
style: FilledButton.styleFrom(
backgroundColor: isTaken
? Colors.white
: _MedicationCheckInPageState._visual.color,
foregroundColor: isTaken
? AppTheme.success
: Colors.white,
disabledBackgroundColor: AppColors.cardInner,
disabledForegroundColor: AppColors.textHint,
padding: const EdgeInsets.symmetric(horizontal: 12),
minimumSize: const Size(0, 36),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(
color: isTaken
? AppTheme.success.withValues(alpha: 0.34)
: Colors.transparent,
),
),
),
icon: isBusy
? const SizedBox(
width: 14,
height: 14,
child: CircularProgressIndicator(
strokeWidth: 2,
color: AppColors.textHint,
),
)
: Icon(
isTaken
? Icons.undo_rounded
: Icons.check_rounded,
size: 17,
),
label: Text(
isTaken ? '撤销' : '打卡',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w800,
),
),
),
),
],
),
if (!isLast)
const Positioned(
left: 96,
right: 0,
bottom: 0,
child: Divider(
height: 1,
thickness: 0.7,
color: AppColors.divider,
),
),
),
],
),
);
}
}
bool _isTaken(Map<String, dynamic> dose) {
return dose['status']?.toString().toLowerCase() == 'taken';
}
bool _isTaken(Map<String, dynamic> dose) =>
dose['status']?.toString().toLowerCase() == 'taken';
String _formatTime(String raw) {
final value = raw.trim();
if (value.length >= 5 && value[2] == ':') return value.substring(0, 5);
final parsed = DateTime.tryParse(value);
if (parsed == null) return value;
final hour = parsed.hour.toString().padLeft(2, '0');
final minute = parsed.minute.toString().padLeft(2, '0');
return '$hour:$minute';
return value.length >= 5 ? value.substring(0, 5) : value;
}
String _statusLabel(String status) => switch (status) {
'taken' => '已完成',
'overdue' => '已超时',
'upcoming' => '待完成',
'skipped' => '已跳过',
_ => '未到时间',
};
Color _statusColor(String status) => switch (status) {
'taken' => AppColors.successText,
'overdue' => AppColors.errorText,
'upcoming' => AppColors.blueMeasure,
'skipped' => AppColors.textHint,
_ => AppColors.textHint,
};