feat: 严格确保万托林先行吸入,退出会话界面不中断计时(支持后台持续倒计时与主页悬浮卡片)

This commit is contained in:
shen
2026-10-27 06:36:48 -07:00
parent f0f45cfb74
commit 394bb727c7
5 changed files with 883 additions and 513 deletions
+349 -506
View File
@@ -1,41 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:uuid/uuid.dart';
import '../models/canister.dart';
import '../models/app_settings.dart';
import '../models/dose_record.dart';
import '../services/storage_service.dart';
import '../services/tts_service.dart';
import '../services/sync_service.dart';
import '../services/audio_service.dart';
enum StepType {
inhale, // 正在吸入某药某喷
intraPuffWait, // 同药两喷之间等待 (30s)
crossDrugWait, // 两药之间等待 (默认 5min,可调)
finished, // 全部完成
}
class SessionStep {
final StepType type;
final Canister? canister;
final int puffIndex; // 第几喷 (1-based)
final int totalPuffs; // 该药共几喷
int durationSeconds; // 倒计时时长 (秒)
final String title;
final String subtitle;
SessionStep({
required this.type,
this.canister,
this.puffIndex = 1,
this.totalPuffs = 1,
required this.durationSeconds,
required this.title,
required this.subtitle,
});
}
import '../services/active_session_service.dart';
class SessionScreen extends StatefulWidget {
final StorageService storageService;
@@ -52,234 +18,67 @@ class SessionScreen extends StatefulWidget {
}
class _SessionScreenState extends State<SessionScreen> {
late AppSettings _settings;
late DateTime _sessionStartTime;
DateTime? _sessionEndTime;
final List<SessionStep> _steps = [];
int _currentStepIndex = 0;
Timer? _timer;
int _remainingSeconds = 0;
int _totalStageSeconds = 0;
bool _rinsedMouth = true;
bool _washedFace = true;
bool _isWaitingForNextMed = false;
final ActiveSessionService _sessionService = ActiveSessionService();
@override
void initState() {
super.initState();
_settings = widget.storageService.getSettings();
_sessionStartTime = DateTime.now();
_sessionService.addListener(_onSessionUpdate);
_buildStepsPipeline();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_steps.isNotEmpty) {
_startStep(0);
}
});
}
void _buildStepsPipeline() {
_steps.clear();
for (int i = 0; i < widget.activeMedications.length; i++) {
final med = widget.activeMedications[i];
for (int p = 1; p <= med.puffsPerSession; p++) {
// 吸入步骤
_steps.add(
SessionStep(
type: StepType.inhale,
canister: med,
puffIndex: p,
totalPuffs: med.puffsPerSession,
durationSeconds: med.inhalationSeconds,
title: '吸入 ${med.name}',
subtitle: '第 $p / ${med.puffsPerSession} 喷 • 面罩紧贴口鼻,平稳深呼吸',
),
);
// 如果同药还有下一喷,插入 30 秒同药间隔
if (p < med.puffsPerSession) {
_steps.add(
SessionStep(
type: StepType.intraPuffWait,
canister: med,
puffIndex: p,
totalPuffs: med.puffsPerSession,
durationSeconds: _settings.intraPuffIntervalSeconds,
title: '${med.name} 连喷间隔',
subtitle: '请间隔 30 秒使药雾沉降并重新摇匀,切勿连喷',
),
);
}
}
// 如果后面还有其他药物,插入多药跨药间隔 (默认 5 分钟)
if (i < widget.activeMedications.length - 1) {
final nextMed = widget.activeMedications[i + 1];
_steps.add(
SessionStep(
type: StepType.crossDrugWait,
canister: med,
durationSeconds: _settings.crossDrugIntervalSeconds,
title: '两药间隔等待 (建议 5 分钟)',
subtitle: '${med.name} 舒张气道中,到点后将提示吸入 ${nextMed.name}',
),
);
}
// 若当前未在执行雾化,则开启新的会话
if (!_sessionService.isActive && widget.activeMedications.isNotEmpty) {
final settings = widget.storageService.getSettings();
_sessionService.startNewSession(
medications: widget.activeMedications,
settings: settings,
);
}
}
@override
void dispose() {
_timer?.cancel();
TtsService().stop();
_sessionService.removeListener(_onSessionUpdate);
// 注意:退出界面绝不销毁计时器!ActiveSessionService 在后台继续计时与语音提醒
super.dispose();
}
void _triggerFeedback({bool isFinished = false}) {
if (_settings.enableVibration) {
HapticFeedback.heavyImpact();
}
if (_settings.enableSound) {
if (isFinished) {
AudioService().playSessionComplete();
} else {
AudioService().playStepComplete();
void _onSessionUpdate() {
if (mounted) setState(() {});
}
Future<void> _confirmAbortSession() async {
final confirmed = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('放弃本次雾化?'),
content: const Text('放弃后将重置当前的雾化与倒计时进度,不会扣除药瓶剩余喷数。'),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: const Text('继续雾化'),
),
ElevatedButton(
onPressed: () => Navigator.pop(ctx, true),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.redAccent,
foregroundColor: Colors.white,
),
child: const Text('确认放弃'),
),
],
),
);
if (confirmed == true) {
_sessionService.cancelSession();
if (mounted) {
Navigator.of(context).pop(false);
}
}
}
void _speakStep(SessionStep step) {
if (!_settings.enableVoicePrompt) return;
if (step.type == StepType.inhale) {
final medName = step.canister?.name.split(" ")[0] ?? '药物';
TtsService().speak('请吸入$medName第${step.puffIndex}喷,口鼻密闭,慢而深地吸气。');
} else if (step.type == StepType.intraPuffWait) {
TtsService().speak('第${step.puffIndex}喷吸入完成,请等待三十秒后吸入下一喷。');
} else if (step.type == StepType.crossDrugWait) {
final minutes = step.durationSeconds ~/ 60;
TtsService().speak('两药间隔开始,请等待$minutes分钟,待气道充分扩张。');
}
}
void _startStep(int index) {
if (index >= _steps.length) {
_finishSession();
return;
}
final step = _steps[index];
_timer?.cancel();
setState(() {
_currentStepIndex = index;
_remainingSeconds = step.durationSeconds;
_totalStageSeconds = step.durationSeconds;
});
_speakStep(step);
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (_remainingSeconds > 1) {
setState(() {
_remainingSeconds--;
});
} else {
timer.cancel();
_onStepCompleted();
}
});
}
void _onStepCompleted() {
_triggerFeedback();
if (_currentStepIndex < _steps.length) {
final currentStep = _steps[_currentStepIndex];
// 如果当前是两药间隔等待,到点后提醒用户,并等待手动点击确认后再开始第二种药物
if (currentStep.type == StepType.crossDrugWait && _currentStepIndex + 1 < _steps.length) {
_timer?.cancel();
if (_settings.enableSound) {
AudioService().playSessionComplete();
}
final nextMed = _steps[_currentStepIndex + 1].canister;
final nextName = nextMed?.name.split(' ')[0] ?? '第二组药物';
if (_settings.enableVoicePrompt) {
TtsService().speak('两药间隔等待已结束!气道已充分舒张。请换上$nextName,戴好面罩后点击屏幕开始吸入。');
}
setState(() {
_isWaitingForNextMed = true;
});
return;
}
}
if (_currentStepIndex + 1 < _steps.length) {
_startStep(_currentStepIndex + 1);
} else {
_finishSession();
}
}
void _finishSession() {
_timer?.cancel();
_sessionEndTime = DateTime.now();
_triggerFeedback(isFinished: true);
if (_settings.enableVoicePrompt) {
Future.delayed(const Duration(milliseconds: 1000), () {
if (mounted) {
TtsService().speak('本次雾化吸入已全部完成,请及时用清水漱口并洗脸!');
}
});
}
setState(() {
_currentStepIndex = _steps.length; // 进入完成态
});
}
void _adjustCurrentTime(int deltaSeconds) {
setState(() {
final newRemaining = (_remainingSeconds + deltaSeconds).clamp(1, 1800);
_remainingSeconds = newRemaining;
if (_currentStepIndex < _steps.length) {
_steps[_currentStepIndex].durationSeconds = newRemaining;
}
});
}
Future<void> _saveAndExit() async {
final Map<String, int> deductions = {};
int totalFlixotide = 0;
int totalVentolin = 0;
for (var med in widget.activeMedications) {
deductions[med.id] = med.puffsPerSession;
if (med.isSteroid) {
totalFlixotide += med.puffsPerSession;
} else {
totalVentolin += med.puffsPerSession;
}
}
final record = DoseRecord(
id: const Uuid().v4(),
startTime: _sessionStartTime,
endTime: _sessionEndTime ?? DateTime.now(),
flixotidePuffs: totalFlixotide,
ventolinPuffs: totalVentolin,
rinsedMouth: _rinsedMouth,
washedFace: _washedFace,
);
await widget.storageService.deductSessionDoses(deductions);
await widget.storageService.addRecord(record);
SyncService(widget.storageService).syncSilently();
await _sessionService.confirmAndSave(widget.storageService);
if (mounted) {
Navigator.of(context).pop(true);
}
@@ -293,90 +92,129 @@ class _SessionScreenState extends State<SessionScreen> {
@override
Widget build(BuildContext context) {
if (_currentStepIndex >= _steps.length) {
if (!_sessionService.isActive) {
return Scaffold(
backgroundColor: const Color(0xFF0F172A),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('当前无进行中的雾化会话', style: TextStyle(color: Colors.white)),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('返回首页'),
),
],
),
),
);
}
if (_sessionService.isFinished) {
return _buildFinishedView();
}
if (_isWaitingForNextMed && _currentStepIndex + 1 < _steps.length) {
return _buildWaitingForNextMedView(_steps[_currentStepIndex + 1]);
if (_sessionService.isWaitingForNextMed && _sessionService.nextStep != null) {
return _buildWaitingForNextMedView(_sessionService.nextStep!);
}
final step = _sessionService.currentStep;
if (step == null) {
return _buildFinishedView();
}
final step = _steps[_currentStepIndex];
final isCross = step.type == StepType.crossDrugWait;
return Scaffold(
backgroundColor: const Color(0xFF0F172A),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
foregroundColor: Colors.white,
title: Text(
'雾化中 (${_currentStepIndex + 1}/${_steps.length})',
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
actions: [
TextButton(
return PopScope(
canPop: true, // 允许返回主页,后台继续计时
child: Scaffold(
backgroundColor: const Color(0xFF0F172A),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
foregroundColor: Colors.white,
leading: IconButton(
icon: const Icon(Icons.arrow_back),
tooltip: '返回主页 (后台继续计时)',
onPressed: () => Navigator.of(context).pop(),
child: const Text('退出', style: TextStyle(color: Colors.white70)),
),
],
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Column(
children: [
// 顶部步骤徽章
_buildStepBadge(step),
title: Text(
'雾化中 (${_sessionService.currentStepIndex + 1}/${_sessionService.steps.length})',
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
actions: [
TextButton(
onPressed: _confirmAbortSession,
child: const Text('放弃本次', style: TextStyle(color: Colors.redAccent, fontSize: 13)),
),
],
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Column(
children: [
// 顶部步骤徽章
_buildStepBadge(step),
const SizedBox(height: 24),
const SizedBox(height: 20),
Text(
step.title,
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Text(
step.subtitle,
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.white60, fontSize: 13),
),
Text(
step.title,
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Text(
step.subtitle,
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.white60, fontSize: 13),
),
const Spacer(),
const Spacer(),
// 倒计时核心大表盘
_buildTimerDial(isCross),
// 倒计时核心大表盘
_buildTimerDial(isCross),
const SizedBox(height: 16),
const SizedBox(height: 16),
// 动态调节时间微调器
_buildTimeAdjustControls(isCross),
// 动态调节时间微调器
_buildTimeAdjustControls(isCross),
const Spacer(),
const Spacer(),
// 下一步按钮
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: _onStepCompleted,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2563EB),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
elevation: 0,
),
child: Text(
_currentStepIndex + 1 < _steps.length ? '下一步 / 提前进入下一阶段' : '完成雾化',
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
// 提示文字
Text(
isCross ? '💡 返回主页计时不会中断,到点将自动响铃与语音提醒' : '💡 返回主页后台持续计时,再次点击即可返回全屏',
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.white38, fontSize: 11),
),
const SizedBox(height: 10),
// 下一步按钮
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () => _sessionService.completeCurrentStep(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2563EB),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
elevation: 0,
),
child: Text(
_sessionService.currentStepIndex + 1 < _sessionService.steps.length ? '下一步 / 提前进入下一阶段' : '完成雾化',
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
),
),
),
),
],
),
],
],
),
],
),
),
),
),
@@ -399,7 +237,7 @@ class _SessionScreenState extends State<SessionScreen> {
label = '万托林 (舒张气道)';
}
} else if (step.type == StepType.intraPuffWait) {
label = '同药两喷间隔';
label = '同药两喷间隔 (30秒)';
} else if (step.type == StepType.crossDrugWait) {
bg = Colors.amber.withValues(alpha: 0.2);
fg = Colors.amberAccent;
@@ -421,8 +259,8 @@ class _SessionScreenState extends State<SessionScreen> {
}
Widget _buildTimerDial(bool isCross) {
final progress = _totalStageSeconds > 0
? (_remainingSeconds / _totalStageSeconds).clamp(0.0, 1.0)
final progress = _sessionService.totalStageSeconds > 0
? (_sessionService.remainingSeconds / _sessionService.totalStageSeconds).clamp(0.0, 1.0)
: 0.0;
return Center(
@@ -448,7 +286,7 @@ class _SessionScreenState extends State<SessionScreen> {
mainAxisSize: MainAxisSize.min,
children: [
Text(
_formatTime(_remainingSeconds),
_formatTime(_sessionService.remainingSeconds),
style: const TextStyle(
fontSize: 48,
fontWeight: FontWeight.w900,
@@ -477,7 +315,7 @@ class _SessionScreenState extends State<SessionScreen> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
OutlinedButton.icon(
onPressed: () => _adjustCurrentTime(-delta),
onPressed: () => _sessionService.adjustCurrentTime(-delta),
style: OutlinedButton.styleFrom(
foregroundColor: Colors.white70,
side: const BorderSide(color: Colors.white24),
@@ -488,7 +326,7 @@ class _SessionScreenState extends State<SessionScreen> {
),
const SizedBox(width: 16),
OutlinedButton.icon(
onPressed: () => _adjustCurrentTime(delta),
onPressed: () => _sessionService.adjustCurrentTime(delta),
style: OutlinedButton.styleFrom(
foregroundColor: Colors.white70,
side: const BorderSide(color: Colors.white24),
@@ -501,11 +339,198 @@ class _SessionScreenState extends State<SessionScreen> {
);
}
Widget _buildWaitingForNextMedView(SessionStep nextStep) {
final nextMed = nextStep.canister;
final nextName = nextMed?.name ?? '第二种药物';
final shortName = nextName.split(' ')[0];
final isSteroid = nextMed?.isSteroid ?? false;
return PopScope(
canPop: true,
child: Scaffold(
backgroundColor: const Color(0xFF0F172A),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
foregroundColor: Colors.white,
leading: IconButton(
icon: const Icon(Icons.arrow_back),
tooltip: '返回主页',
onPressed: () => Navigator.of(context).pop(),
),
title: const Text(
'两药间隔等待结束',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
actions: [
TextButton(
onPressed: _confirmAbortSession,
child: const Text('放弃本次', style: TextStyle(color: Colors.redAccent, fontSize: 13)),
),
],
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Column(
children: [
// 状态标志
Container(
width: 64,
height: 64,
decoration: BoxDecoration(
color: const Color(0xFF10B981).withValues(alpha: 0.15),
shape: BoxShape.circle,
border: Border.all(color: const Color(0xFF10B981), width: 2),
),
child: const Icon(Icons.check, color: Color(0xFF10B981), size: 36),
),
const SizedBox(height: 16),
const Text(
'两药间隔倒计时已结束',
style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 6),
const Text(
'气道已充分舒张吸收,已暂停等待手动开始',
style: TextStyle(color: Color(0xFF94A3B8), fontSize: 13),
),
const SizedBox(height: 24),
// 第二组药物卡片
Container(
width: double.infinity,
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: isSteroid ? const Color(0xFF059669) : const Color(0xFF2563EB),
width: 1.5,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: isSteroid
? const Color(0xFF10B981).withValues(alpha: 0.2)
: const Color(0xFF2563EB).withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
isSteroid ? '辅' : '万',
style: TextStyle(
color: isSteroid ? const Color(0xFF34D399) : const Color(0xFF60A5FA),
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'准备开始第二组用药',
style: TextStyle(
fontSize: 12,
color: isSteroid ? const Color(0xFF34D399) : const Color(0xFF60A5FA),
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 2),
Text(
nextName,
style: const TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
const SizedBox(height: 14),
const Divider(color: Colors.white12, height: 1),
const SizedBox(height: 14),
Text(
'计划用药:${nextMed?.puffsPerSession ?? 1} 喷 • 单喷吸气时长 ${nextMed?.inhalationSeconds ?? 15} 秒',
style: const TextStyle(fontSize: 13, color: Color(0xFFCBD5E1), fontWeight: FontWeight.w600),
),
const SizedBox(height: 12),
_buildCheckTip('1. 请取下前序药物,换上【$shortName】并充分摇匀'),
_buildCheckTip('2. 将储雾罐面罩紧贴口鼻,保持自然平静呼吸'),
_buildCheckTip('3. 一切就绪后,按压药瓶并点击下方按钮开始吸入'),
],
),
),
const Spacer(),
// 手动开始第二组大按钮
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () => _sessionService.startNextMedication(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2563EB),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 18),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
elevation: 4,
),
icon: const Icon(Icons.play_arrow_rounded, size: 26),
label: Text(
'开始吸入【$shortName】第 1 喷',
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
),
),
],
),
),
),
),
);
}
Widget _buildCheckTip(String text) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('• ', style: TextStyle(color: Color(0xFF38BDF8), fontSize: 13, fontWeight: FontWeight.bold)),
Expanded(
child: Text(
text,
style: const TextStyle(color: Color(0xFF94A3B8), fontSize: 12, height: 1.4),
),
),
],
),
);
}
Widget _buildFinishedView() {
final duration = (_sessionEndTime ?? DateTime.now()).difference(_sessionStartTime);
final startTime = _sessionService.sessionStartTime ?? DateTime.now();
final endTime = _sessionService.sessionEndTime ?? DateTime.now();
final duration = endTime.difference(startTime);
final minutes = duration.inMinutes;
final seconds = duration.inSeconds % 60;
final hasSteroid = widget.activeMedications.any((m) => m.isSteroid);
final hasSteroid = _sessionService.activeMedications.any((m) => m.isSteroid);
return Scaffold(
backgroundColor: Colors.white,
@@ -543,7 +568,7 @@ class _SessionScreenState extends State<SessionScreen> {
const SizedBox(height: 24),
// 漱口洗脸 Checklist (当吸入了含激素药物如辅舒酮时显示)
// 漱口洗脸 Checklist
if (hasSteroid) ...[
Container(
padding: const EdgeInsets.all(16),
@@ -568,17 +593,17 @@ class _SessionScreenState extends State<SessionScreen> {
const SizedBox(height: 10),
CheckboxListTile(
contentPadding: EdgeInsets.zero,
value: _rinsedMouth,
value: _sessionService.rinsedMouth,
activeColor: const Color(0xFF10B981),
title: const Text('清水彻底漱口并吐出 (防鹅口疮/声音嘶哑)', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600)),
onChanged: (val) => setState(() => _rinsedMouth = val ?? true),
onChanged: (val) => _sessionService.rinsedMouth = val ?? true,
),
CheckboxListTile(
contentPadding: EdgeInsets.zero,
value: _washedFace,
value: _sessionService.washedFace,
activeColor: const Color(0xFF10B981),
title: const Text('温水擦洗面部口鼻区域 (防皮炎)', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600)),
onChanged: (val) => setState(() => _washedFace = val ?? true),
onChanged: (val) => _sessionService.washedFace = val ?? true,
),
],
),
@@ -595,7 +620,7 @@ class _SessionScreenState extends State<SessionScreen> {
border: Border.all(color: const Color(0xFFE2E8F0)),
),
child: Column(
children: widget.activeMedications.map((m) {
children: _sessionService.activeMedications.map((m) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
@@ -631,186 +656,4 @@ class _SessionScreenState extends State<SessionScreen> {
),
);
}
Widget _buildWaitingForNextMedView(SessionStep nextStep) {
final nextMed = nextStep.canister;
final nextName = nextMed?.name ?? '第二种药物';
final shortName = nextName.split(' ')[0];
final isSteroid = nextMed?.isSteroid ?? false;
return Scaffold(
backgroundColor: const Color(0xFF0F172A),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
foregroundColor: Colors.white,
title: const Text(
'两药间隔等待结束',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('退出', style: TextStyle(color: Colors.white70)),
),
],
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Column(
children: [
// 状态标志
Container(
width: 64,
height: 64,
decoration: BoxDecoration(
color: const Color(0xFF10B981).withValues(alpha: 0.15),
shape: BoxShape.circle,
border: Border.all(color: const Color(0xFF10B981), width: 2),
),
child: const Icon(Icons.check, color: Color(0xFF10B981), size: 36),
),
const SizedBox(height: 16),
const Text(
'两药间隔倒计时已结束',
style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 6),
const Text(
'气道已充分舒张吸收,已暂停等待手动开始',
style: TextStyle(color: Color(0xFF94A3B8), fontSize: 13),
),
const SizedBox(height: 24),
// 第二组药物卡片
Container(
width: double.infinity,
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: isSteroid ? const Color(0xFF059669) : const Color(0xFF2563EB),
width: 1.5,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: isSteroid
? const Color(0xFF10B981).withValues(alpha: 0.2)
: const Color(0xFF2563EB).withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
isSteroid ? '辅' : '万',
style: TextStyle(
color: isSteroid ? const Color(0xFF34D399) : const Color(0xFF60A5FA),
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'准备开始第二组用药',
style: TextStyle(
fontSize: 12,
color: isSteroid ? const Color(0xFF34D399) : const Color(0xFF60A5FA),
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 2),
Text(
nextName,
style: const TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
const SizedBox(height: 14),
const Divider(color: Colors.white12, height: 1),
const SizedBox(height: 14),
Text(
'计划用药:${nextMed?.puffsPerSession ?? 1} 喷 • 单喷吸气时长 ${nextMed?.inhalationSeconds ?? 15} 秒',
style: const TextStyle(fontSize: 13, color: Color(0xFFCBD5E1), fontWeight: FontWeight.w600),
),
const SizedBox(height: 12),
_buildCheckTip('1. 请取下前序药物,换上【$shortName】并充分摇匀'),
_buildCheckTip('2. 将储雾罐面罩紧贴口鼻,保持自然平静呼吸'),
_buildCheckTip('3. 一切就绪后,按压药瓶并点击下方按钮开始吸入'),
],
),
),
const Spacer(),
// 手动开始第二组大按钮
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () {
setState(() {
_isWaitingForNextMed = false;
});
_startStep(_currentStepIndex + 1);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2563EB),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 18),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
elevation: 4,
),
icon: const Icon(Icons.play_arrow_rounded, size: 26),
label: Text(
'开始吸入【$shortName】第 1 喷',
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
),
),
],
),
),
),
);
}
Widget _buildCheckTip(String text) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('• ', style: TextStyle(color: Color(0xFF38BDF8), fontSize: 13, fontWeight: FontWeight.bold)),
Expanded(
child: Text(
text,
style: const TextStyle(color: Color(0xFF94A3B8), fontSize: 12, height: 1.4),
),
),
],
),
);
}
}