feat: initial commit for AeroTrack Flutter app
This commit is contained in:
@@ -0,0 +1,241 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/app_settings.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../services/tts_service.dart';
|
||||
import 'plan_config_screen.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
final StorageService storageService;
|
||||
|
||||
const SettingsScreen({super.key, required this.storageService});
|
||||
|
||||
@override
|
||||
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
late AppSettings _settings;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_settings = widget.storageService.getSettings();
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
await widget.storageService.saveSettings(_settings);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('设置已保存')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _resetFlixotide() async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('启用新药瓶 - 辅舒酮'),
|
||||
content: const Text('确认启用新的一瓶辅舒酮,将其剩余次数重置为 60 喷吗?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: const Text('确认重置为 60 喷'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
final flixotide = widget.storageService.getPrimaryFlixotide();
|
||||
if (flixotide != null) {
|
||||
await widget.storageService.resetCanisterDoses(flixotide.id, 60);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('已成功将辅舒酮重置为 60 喷!')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _resetVentolin() async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('启用新药瓶 - 万托林'),
|
||||
content: const Text('确认启用新的一瓶万托林,将其剩余次数重置为 200 喷吗?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: const Text('确认重置为 200 喷'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
final ventolin = widget.storageService.getPrimaryVentolin();
|
||||
if (ventolin != null) {
|
||||
await widget.storageService.resetCanisterDoses(ventolin.id, 200);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('已成功将万托林重置为 200 喷!')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8FAFC),
|
||||
appBar: AppBar(
|
||||
title: const Text('系统设置与药瓶管理', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
foregroundColor: const Color(0xFF0F172A),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
children: [
|
||||
// 方案配置入口卡
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF2563EB), Color(0xFF1D4ED8)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
leading: const Icon(Icons.medication_liquid, color: Colors.white, size: 28),
|
||||
title: const Text(
|
||||
'药物与雾化方案配置',
|
||||
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 15),
|
||||
),
|
||||
subtitle: const Text(
|
||||
'勾选当前使用的药物、喷数、吸气时间与多药间隔',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_forward_ios, color: Colors.white70, size: 16),
|
||||
onTap: () async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => PlanConfigScreen(storageService: widget.storageService),
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
_settings = widget.storageService.getSettings();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 模块 2:提醒偏好
|
||||
const Text('提醒与反馈', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: Colors.grey)),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: const Color(0xFFE2E8F0)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
title: const Text('提示音效', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
|
||||
subtitle: const Text('倒计时结束时发出提示音', style: TextStyle(fontSize: 12)),
|
||||
value: _settings.enableSound,
|
||||
activeTrackColor: const Color(0xFF2563EB),
|
||||
onChanged: (val) {
|
||||
setState(() => _settings.enableSound = val);
|
||||
_save();
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
SwitchListTile(
|
||||
title: const Text('触觉震动', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
|
||||
subtitle: const Text('倒计时结束时震动提示', style: TextStyle(fontSize: 12)),
|
||||
value: _settings.enableVibration,
|
||||
activeTrackColor: const Color(0xFF2563EB),
|
||||
onChanged: (val) {
|
||||
setState(() => _settings.enableVibration = val);
|
||||
_save();
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
SwitchListTile(
|
||||
title: const Text('真人语音播报', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
|
||||
subtitle: const Text('做完时自动播报“本次雾化吸入已全部完成,请及时用清水漱口并洗脸”', style: TextStyle(fontSize: 12)),
|
||||
value: _settings.enableVoicePrompt,
|
||||
activeTrackColor: const Color(0xFF2563EB),
|
||||
onChanged: (val) {
|
||||
setState(() => _settings.enableVoicePrompt = val);
|
||||
_save();
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 12),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
TtsService().speak('本次雾化吸入已全部完成,请及时用清水漱口并洗脸!');
|
||||
},
|
||||
style: OutlinedButton.styleFrom(
|
||||
visualDensity: VisualDensity.compact,
|
||||
side: const BorderSide(color: Color(0xFFBFDBFE)),
|
||||
),
|
||||
icon: const Icon(Icons.volume_up, size: 16, color: Color(0xFF2563EB)),
|
||||
label: const Text('🔊 点击试听语音播报效果', style: TextStyle(fontSize: 12, color: Color(0xFF2563EB))),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 模块 3:药瓶管理与新瓶重置
|
||||
const Text('药瓶库存管理与开新瓶重置', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: Colors.grey)),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: const Color(0xFFE2E8F0)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.refresh, color: Color(0xFF10B981)),
|
||||
title: const Text('开封新瓶:辅舒酮 (重置为 60 喷)', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
|
||||
subtitle: const Text('旧瓶用完或换新药瓶时点击重置', style: TextStyle(fontSize: 12)),
|
||||
onTap: _resetFlixotide,
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.refresh, color: Color(0xFF2563EB)),
|
||||
title: const Text('开封新瓶:万托林 (重置为 200 喷)', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
|
||||
subtitle: const Text('旧瓶用完或换新药瓶时点击重置', style: TextStyle(fontSize: 12)),
|
||||
onTap: _resetVentolin,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user