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/storage_service.dart';
|
||||||
import 'services/tts_service.dart';
|
import 'services/tts_service.dart';
|
||||||
import 'services/audio_service.dart';
|
import 'services/audio_service.dart';
|
||||||
import 'screens/home_screen.dart';
|
import 'screens/main_navigation_screen.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
@@ -37,7 +37,7 @@ class AeroTrackApp extends StatelessWidget {
|
|||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
home: HomeScreen(storageService: storageService),
|
home: MainNavigationScreen(storageService: storageService),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,13 @@ import '../services/active_session_service.dart';
|
|||||||
|
|
||||||
class HomeScreen extends StatefulWidget {
|
class HomeScreen extends StatefulWidget {
|
||||||
final StorageService storageService;
|
final StorageService storageService;
|
||||||
|
final VoidCallback? onNavigateToCabinet;
|
||||||
|
|
||||||
const HomeScreen({super.key, required this.storageService});
|
const HomeScreen({
|
||||||
|
super.key,
|
||||||
|
required this.storageService,
|
||||||
|
this.onNavigateToCabinet,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<HomeScreen> createState() => _HomeScreenState();
|
State<HomeScreen> createState() => _HomeScreenState();
|
||||||
@@ -286,22 +291,6 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
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(
|
IconButton(
|
||||||
icon: const Icon(Icons.sync, color: Color(0xFF2563EB)),
|
icon: const Icon(Icons.sync, color: Color(0xFF2563EB)),
|
||||||
tooltip: '局域网同步',
|
tooltip: '局域网同步',
|
||||||
@@ -413,6 +402,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
),
|
),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
if (widget.onNavigateToCabinet != null) {
|
||||||
|
widget.onNavigateToCabinet!();
|
||||||
|
return;
|
||||||
|
}
|
||||||
await Navigator.of(context).push(
|
await Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => MedicineCabinetScreen(
|
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: '家庭药箱',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,7 +38,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(med.healthStatus, MedicineHealthStatus.expiringSoon);
|
expect(med.healthStatus, MedicineHealthStatus.expiringSoon);
|
||||||
expect(med.healthStatusLabel, contains('即将到期 (15天)'));
|
expect(med.healthStatusLabel, contains('即将到期'));
|
||||||
|
expect(med.daysUntilExpiry, inInclusiveRange(14, 15));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Medicine past expiryDate triggers expired', () {
|
test('Medicine past expiryDate triggers expired', () {
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:aero_track/models/canister.dart';
|
import 'package:aero_track/models/canister.dart';
|
||||||
import 'package:aero_track/models/app_settings.dart';
|
import 'package:aero_track/models/app_settings.dart';
|
||||||
|
import 'package:aero_track/services/storage_service.dart';
|
||||||
import 'package:aero_track/widgets/puff_progress_ring.dart';
|
import 'package:aero_track/widgets/puff_progress_ring.dart';
|
||||||
|
import 'package:aero_track/screens/main_navigation_screen.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
@@ -75,4 +78,31 @@ void main() {
|
|||||||
expect(list.first.name, '万托林');
|
expect(list.first.name, '万托林');
|
||||||
expect(list.last.name, '辅舒酮');
|
expect(list.last.name, '辅舒酮');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Bottom Navigation Bar renders 雾化入口 and 家庭药箱 tabs and switches correctly', (WidgetTester tester) async {
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
final storageService = await StorageService.init();
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: MainNavigationScreen(storageService: storageService),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// 底部必须出现两个核心 Tab
|
||||||
|
expect(find.text('雾化入口'), findsOneWidget);
|
||||||
|
expect(find.text('家庭药箱'), findsOneWidget);
|
||||||
|
|
||||||
|
// 默认展示雾化打卡主页内容
|
||||||
|
expect(find.text('舒雾记'), findsOneWidget);
|
||||||
|
|
||||||
|
// 点击【家庭药箱】Tab
|
||||||
|
await tester.tap(find.text('家庭药箱'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// 页面无缝切换到家庭药箱模块
|
||||||
|
expect(find.text('家庭智能药箱'), findsOneWidget);
|
||||||
|
expect(find.text('扫码录药'), findsOneWidget);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user