feat(ui): 首页提醒条升级为今日雾化状态,显示今日次数及早晚完成情况
- 统计今日雾化次数(排除试喷记录),按早晚提醒时间中点划分早间/晚间 - 已完成显示完成时间;超过提醒时间未做标橙提示;早晚均完成变绿 - 点击提醒条弹出今日雾化明细 - 修复底部“上次完成”误将试喷记录显示为雾化的问题 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3f3e9855db
commit
d322ae4d87
+176
-16
@@ -35,6 +35,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
late List<Canister> _activeCanisters;
|
||||
late AppSettings _settings;
|
||||
DoseRecord? _lastRecord;
|
||||
List<DoseRecord> _todayRecords = [];
|
||||
final ActiveSessionService _sessionService = ActiveSessionService();
|
||||
|
||||
@override
|
||||
@@ -64,11 +65,94 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
_ventolin = widget.storageService.getPrimaryVentolin()!;
|
||||
_activeCanisters = widget.storageService.getActiveCanisters();
|
||||
_settings = widget.storageService.getSettings();
|
||||
final records = widget.storageService.getRecords();
|
||||
// 排除试喷扣除记录,只统计真实雾化
|
||||
final records = widget.storageService.getRecords().where((r) => !r.isPrime).toList();
|
||||
_lastRecord = records.isNotEmpty ? records.first : null;
|
||||
final now = DateTime.now();
|
||||
_todayRecords = records.where((r) {
|
||||
final t = r.startTime.toLocal();
|
||||
return t.year == now.year && t.month == now.month && t.day == now.day;
|
||||
}).toList()
|
||||
..sort((a, b) => a.startTime.compareTo(b.startTime));
|
||||
});
|
||||
}
|
||||
|
||||
/// 早/晚时段分界点(当天分钟数):取早间与晚间提醒时间的中点
|
||||
int get _sessionSplitMinute {
|
||||
final m = _settings.morningReminderHour * 60 + _settings.morningReminderMinute;
|
||||
final e = _settings.eveningReminderHour * 60 + _settings.eveningReminderMinute;
|
||||
return e > m ? (m + e) ~/ 2 : 12 * 60;
|
||||
}
|
||||
|
||||
bool _isMorningRecord(DoseRecord r) {
|
||||
final t = r.startTime.toLocal();
|
||||
return t.hour * 60 + t.minute < _sessionSplitMinute;
|
||||
}
|
||||
|
||||
String _recordDetail(DoseRecord r) {
|
||||
final parts = <String>[
|
||||
if (r.ventolinPuffs > 0) '万托林 ${r.ventolinPuffs}喷',
|
||||
if (r.flixotidePuffs > 0) '辅舒酮 ${r.flixotidePuffs}喷',
|
||||
];
|
||||
return parts.isEmpty ? '无喷数' : parts.join(' + ');
|
||||
}
|
||||
|
||||
void _showTodayRecordsSheet() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: Colors.white,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'今日雾化明细(共 ${_todayRecords.length} 次)',
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF0F172A)),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
if (_todayRecords.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Text('今天还没有雾化记录', style: TextStyle(color: Colors.grey, fontSize: 13)),
|
||||
)
|
||||
else
|
||||
..._todayRecords.map((r) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.check_circle, color: Color(0xFF10B981), size: 18),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
DateFormat('HH:mm').format(r.startTime.toLocal()),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: Color(0xFF0F172A)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_isMorningRecord(r) ? '早间' : '晚间',
|
||||
style: const TextStyle(fontSize: 12, color: Color(0xFF64748B)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_recordDetail(r),
|
||||
style: const TextStyle(fontSize: 13, color: Color(0xFF334155)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openPlanConfig() async {
|
||||
final result = await Navigator.of(context).push<bool>(
|
||||
MaterialPageRoute(
|
||||
@@ -605,28 +689,104 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
final mTime = '${_settings.morningReminderHour.toString().padLeft(2, '0')}:${_settings.morningReminderMinute.toString().padLeft(2, '0')}';
|
||||
final eTime = '${_settings.eveningReminderHour.toString().padLeft(2, '0')}:${_settings.eveningReminderMinute.toString().padLeft(2, '0')}';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFEF3C7),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFFDE68A)),
|
||||
),
|
||||
child: Row(
|
||||
final morningDone = _todayRecords.where(_isMorningRecord).toList();
|
||||
final eveningDone = _todayRecords.where((r) => !_isMorningRecord(r)).toList();
|
||||
|
||||
final now = DateTime.now();
|
||||
final nowMinute = now.hour * 60 + now.minute;
|
||||
final morningDue = _settings.morningReminderHour * 60 + _settings.morningReminderMinute;
|
||||
final eveningDue = _settings.eveningReminderHour * 60 + _settings.eveningReminderMinute;
|
||||
final morningOverdue = morningDone.isEmpty && nowMinute >= morningDue;
|
||||
final eveningOverdue = eveningDone.isEmpty && nowMinute >= eveningDue;
|
||||
final allDone = morningDone.isNotEmpty && eveningDone.isNotEmpty;
|
||||
|
||||
// 配色:全部完成=绿;已过提醒时间未做=橙;其余=原黄色
|
||||
final Color bg, border, accent, textColor;
|
||||
if (allDone) {
|
||||
bg = const Color(0xFFD1FAE5);
|
||||
border = const Color(0xFFA7F3D0);
|
||||
accent = const Color(0xFF059669);
|
||||
textColor = const Color(0xFF065F46);
|
||||
} else if (morningOverdue || eveningOverdue) {
|
||||
bg = const Color(0xFFFFEDD5);
|
||||
border = const Color(0xFFFDBA74);
|
||||
accent = const Color(0xFFEA580C);
|
||||
textColor = const Color(0xFF9A3412);
|
||||
} else {
|
||||
bg = const Color(0xFFFEF3C7);
|
||||
border = const Color(0xFFFDE68A);
|
||||
accent = const Color(0xFFD97706);
|
||||
textColor = const Color(0xFF92400E);
|
||||
}
|
||||
|
||||
Widget slotRow(String label, String dueTime, List<DoseRecord> done, bool overdue) {
|
||||
final String status;
|
||||
if (done.isNotEmpty) {
|
||||
final times = done.map((r) => DateFormat('HH:mm').format(r.startTime.toLocal())).join('、');
|
||||
status = done.length > 1 ? '已完成 ${done.length} 次 ($times)' : '已完成 $times';
|
||||
} else {
|
||||
status = overdue ? '未完成(已过时间)' : '待完成';
|
||||
}
|
||||
return Row(
|
||||
children: [
|
||||
const Icon(Icons.access_time_filled, color: Color(0xFFD97706), size: 18),
|
||||
Icon(
|
||||
done.isNotEmpty ? Icons.check_circle : Icons.radio_button_unchecked,
|
||||
size: 16,
|
||||
color: done.isNotEmpty ? const Color(0xFF10B981) : (overdue ? const Color(0xFFEA580C) : accent),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text('$label $dueTime', style: TextStyle(fontSize: 12, color: textColor)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'定时提醒:早间 $mTime • 晚间 $eTime',
|
||||
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: Color(0xFF92400E)),
|
||||
status,
|
||||
style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: textColor),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_activeCanisters.length > 1 ? '当前为双药方案' : '当前为单药方案',
|
||||
style: const TextStyle(fontSize: 11, color: Color(0xFFB45309)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: _showTodayRecordsSheet,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Ink(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.access_time_filled, color: accent, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'今日已雾化 ${_todayRecords.length} 次',
|
||||
style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold, color: textColor),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_activeCanisters.length > 1 ? '当前为双药方案' : '当前为单药方案',
|
||||
style: TextStyle(fontSize: 11, color: accent),
|
||||
),
|
||||
Icon(Icons.chevron_right, color: accent, size: 16),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
slotRow('早间', mTime, morningDone, morningOverdue),
|
||||
const SizedBox(height: 4),
|
||||
slotRow('晚间', eTime, eveningDone, eveningOverdue),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user