feat: 增加全家庭智能药箱功能,支持扫码识别(追溯码/GS1/条形码)、出厂有效期与开封保质期双轨追踪及局域网多设备同步
This commit is contained in:
@@ -5,11 +5,13 @@ import '../models/canister.dart';
|
||||
import '../models/dose_record.dart';
|
||||
import '../models/app_settings.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../models/medicine_item.dart';
|
||||
import 'session_screen.dart';
|
||||
import 'history_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
import 'plan_config_screen.dart';
|
||||
import 'lan_sync_screen.dart';
|
||||
import 'medicine_cabinet_screen.dart';
|
||||
import '../services/sync_service.dart';
|
||||
import '../services/active_session_service.dart';
|
||||
|
||||
@@ -284,6 +286,22 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.medical_services_outlined, color: Color(0xFF059669)),
|
||||
tooltip: '家庭药箱',
|
||||
visualDensity: VisualDensity.compact,
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MedicineCabinetScreen(
|
||||
storageService: widget.storageService,
|
||||
syncService: SyncService(widget.storageService),
|
||||
),
|
||||
),
|
||||
);
|
||||
_loadData();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.sync, color: Color(0xFF2563EB)),
|
||||
tooltip: '局域网同步',
|
||||
@@ -352,6 +370,11 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 模块 3.5:家庭智能药箱看板入口
|
||||
_buildFamilyMedicineCabinetCard(),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 模块 4:最近吸入记录底栏
|
||||
_buildLastRecordFooter(),
|
||||
],
|
||||
@@ -360,6 +383,112 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// 3.5 家庭智能药箱入口卡片
|
||||
Widget _buildFamilyMedicineCabinetCard() {
|
||||
final medicines = widget.storageService.getMedicines();
|
||||
final dangerCount = medicines.where((m) =>
|
||||
m.healthStatus == MedicineHealthStatus.overdueInUse ||
|
||||
m.healthStatus == MedicineHealthStatus.expired).length;
|
||||
final soonCount = medicines.where((m) => m.healthStatus == MedicineHealthStatus.expiringSoon).length;
|
||||
|
||||
Color badgeBg = const Color(0xFFEFF6FF);
|
||||
Color badgeColor = const Color(0xFF2563EB);
|
||||
String badgeText = '${medicines.length} 种在库';
|
||||
|
||||
if (dangerCount > 0) {
|
||||
badgeBg = const Color(0xFFFEF2F2);
|
||||
badgeColor = const Color(0xFFEF4444);
|
||||
badgeText = '⚠️ $dangerCount 种已超期/过期';
|
||||
} else if (soonCount > 0) {
|
||||
badgeBg = const Color(0xFFFEF3C7);
|
||||
badgeColor = const Color(0xFFD97706);
|
||||
badgeText = '🟡 $soonCount 种即将到期';
|
||||
}
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(color: dangerCount > 0 ? Colors.red.shade300 : const Color(0xFFE2E8F0)),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MedicineCabinetScreen(
|
||||
storageService: widget.storageService,
|
||||
syncService: SyncService(widget.storageService),
|
||||
),
|
||||
),
|
||||
);
|
||||
_loadData();
|
||||
},
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFECFDF5),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.medical_services_outlined,
|
||||
color: Color(0xFF059669),
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'家庭智能药箱',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF0F172A),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: badgeBg,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
badgeText,
|
||||
style: TextStyle(
|
||||
color: badgeColor,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
const Text(
|
||||
'出厂有效期与开封保质期智能监控 · 扫码即识',
|
||||
style: TextStyle(fontSize: 12, color: Colors.black54),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.arrow_forward_ios, size: 14, color: Colors.grey),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 0. 进行中雾化实时悬浮卡片 (返回主页不中断计时)
|
||||
Widget _buildActiveSessionBanner() {
|
||||
final step = _sessionService.currentStep;
|
||||
|
||||
Reference in New Issue
Block a user