feat(ui): 升级为底部Tab导航样式,分别提供【雾化入口】与【家庭药箱】
This commit is contained in:
+2
-2
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'services/storage_service.dart';
|
||||
import 'services/tts_service.dart';
|
||||
import 'services/audio_service.dart';
|
||||
import 'screens/home_screen.dart';
|
||||
import 'screens/main_navigation_screen.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -37,7 +37,7 @@ class AeroTrackApp extends StatelessWidget {
|
||||
centerTitle: false,
|
||||
),
|
||||
),
|
||||
home: HomeScreen(storageService: storageService),
|
||||
home: MainNavigationScreen(storageService: storageService),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,13 @@ import '../services/active_session_service.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
final StorageService storageService;
|
||||
final VoidCallback? onNavigateToCabinet;
|
||||
|
||||
const HomeScreen({super.key, required this.storageService});
|
||||
const HomeScreen({
|
||||
super.key,
|
||||
required this.storageService,
|
||||
this.onNavigateToCabinet,
|
||||
});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
@@ -286,22 +291,6 @@ 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: '局域网同步',
|
||||
@@ -413,6 +402,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
if (widget.onNavigateToCabinet != null) {
|
||||
widget.onNavigateToCabinet!();
|
||||
return;
|
||||
}
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MedicineCabinetScreen(
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
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<MainNavigationScreen> createState() => _MainNavigationScreenState();
|
||||
}
|
||||
|
||||
class _MainNavigationScreenState extends State<MainNavigationScreen> {
|
||||
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: '家庭药箱',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user