import 'package:flutter/material.dart'; import '../models/medicine_item.dart'; import '../services/storage_service.dart'; import '../services/sync_service.dart'; import 'home_screen.dart'; import 'medicine_cabinet_screen.dart'; class MainNavigationScreen extends StatefulWidget { final StorageService storageService; const MainNavigationScreen({ super.key, required this.storageService, }); @override State createState() => _MainNavigationScreenState(); } class _MainNavigationScreenState extends State { int _currentIndex = 0; late final SyncService _syncService; @override void initState() { super.initState(); _syncService = SyncService(widget.storageService); } int _getAttentionCount() { final meds = widget.storageService.getMedicines(); return meds.where((m) => m.healthStatus == MedicineHealthStatus.overdueInUse || m.healthStatus == MedicineHealthStatus.expired || m.healthStatus == MedicineHealthStatus.expiringSoon).length; } @override Widget build(BuildContext context) { final attentionCount = _getAttentionCount(); return Scaffold( body: IndexedStack( index: _currentIndex, children: [ HomeScreen( storageService: widget.storageService, onNavigateToCabinet: () { setState(() => _currentIndex = 1); }, ), MedicineCabinetScreen( storageService: widget.storageService, syncService: _syncService, ), ], ), bottomNavigationBar: NavigationBar( selectedIndex: _currentIndex, onDestinationSelected: (index) { setState(() => _currentIndex = index); }, backgroundColor: Colors.white, elevation: 3, indicatorColor: const Color(0xFFEFF6FF), destinations: [ const NavigationDestination( icon: Icon(Icons.air_outlined, color: Color(0xFF64748B)), selectedIcon: Icon(Icons.air, color: Color(0xFF2563EB)), label: '雾化入口', ), NavigationDestination( icon: attentionCount > 0 ? Badge( label: Text('$attentionCount'), backgroundColor: const Color(0xFFEF4444), child: const Icon(Icons.medical_services_outlined, color: Color(0xFF64748B)), ) : const Icon(Icons.medical_services_outlined, color: Color(0xFF64748B)), selectedIcon: attentionCount > 0 ? Badge( label: Text('$attentionCount'), backgroundColor: const Color(0xFFEF4444), child: const Icon(Icons.medical_services, color: Color(0xFF2563EB)), ) : const Icon(Icons.medical_services, color: Color(0xFF2563EB)), label: '家庭药箱', ), ], ), ); } }