## 抽屉重构 - admin_drawer / doctor_drawer / health_drawer 三端抽屉全部重做 - drawer_shell 增强 ## 配色系统 - app_colors / app_module_visuals / app_theme 更新 - app.dart 启动流程调整 ## 后台管理页 - admin_doctors_page 大幅重构(+251) - admin_home / doctor_dashboard / doctor_reports / doctor_home / doctor_followups / doctor_settings 精调 ## 患者端 - home_page / chat_messages_view / medication_list / notification_center / remaining_pages / exercise_plan / device / diet / consultation 微调 ## 新增 - keyboard_lift.dart: 键盘抬起处理组件 - AGENTS.md: agent 指引文档 ## 其他 - api_client IP 适配 - app_future_view 增强 - data_providers 调整 - secondary_page_visuals_test 更新
152 lines
4.5 KiB
Dart
152 lines
4.5 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'auth_provider.dart';
|
|
import '../services/health_service.dart';
|
|
import '../services/admin_service.dart';
|
|
import '../services/in_app_notification_service.dart';
|
|
|
|
final exerciseServiceProvider = Provider<ExerciseService>((ref) {
|
|
return ExerciseService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
/// 健康数据服务
|
|
final healthServiceProvider = Provider<HealthService>((ref) {
|
|
return HealthService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final userServiceProvider = Provider<UserService>((ref) {
|
|
return UserService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final medicationServiceProvider = Provider<MedicationService>((ref) {
|
|
return MedicationService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final dietServiceProvider = Provider<DietService>((ref) {
|
|
return DietService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final followUpServiceProvider = Provider<FollowUpService>((ref) {
|
|
return FollowUpService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final consultationServiceProvider = Provider<ConsultationService>((ref) {
|
|
return ConsultationService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final adminServiceProvider = Provider<AdminService>((ref) {
|
|
return AdminService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final inAppNotificationServiceProvider = Provider<InAppNotificationService>((
|
|
ref,
|
|
) {
|
|
return InAppNotificationService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final notificationUnreadCountProvider = FutureProvider<int>((ref) async {
|
|
final history = await ref
|
|
.watch(inAppNotificationServiceProvider)
|
|
.getHistory();
|
|
return history.unreadCount;
|
|
});
|
|
|
|
/// 最新健康数据 Provider
|
|
final latestHealthProvider = FutureProvider<Map<String, dynamic>>((ref) async {
|
|
final service = ref.watch(healthServiceProvider);
|
|
return service.getLatest();
|
|
});
|
|
|
|
/// 用药列表 Provider
|
|
final medicationListProvider = FutureProvider<List<Map<String, dynamic>>>((
|
|
ref,
|
|
) async {
|
|
final service = ref.watch(medicationServiceProvider);
|
|
return service.getList();
|
|
});
|
|
|
|
final exercisePlansProvider = FutureProvider<List<Map<String, dynamic>>>((
|
|
ref,
|
|
) async {
|
|
return ref.watch(exerciseServiceProvider).getPlans();
|
|
});
|
|
|
|
final followUpListProvider = FutureProvider<List<Map<String, dynamic>>>((
|
|
ref,
|
|
) async {
|
|
return ref.watch(followUpServiceProvider).getList();
|
|
});
|
|
|
|
final dietRecordsProvider = FutureProvider<List<Map<String, dynamic>>>((
|
|
ref,
|
|
) async {
|
|
return ref.watch(dietServiceProvider).getRecords();
|
|
});
|
|
|
|
final medicationReminderProvider = FutureProvider<List<Map<String, dynamic>>>((
|
|
ref,
|
|
) async {
|
|
final service = ref.watch(medicationServiceProvider);
|
|
return service.getReminders();
|
|
});
|
|
|
|
/// 医生列表 Provider
|
|
final doctorListProvider =
|
|
FutureProvider.autoDispose<List<Map<String, dynamic>>>((ref) async {
|
|
final service = ref.watch(consultationServiceProvider);
|
|
return service.getDoctors().timeout(const Duration(seconds: 8));
|
|
});
|
|
|
|
/// 当前运动计划 Provider
|
|
final currentExercisePlanProvider = FutureProvider<Map<String, dynamic>?>((
|
|
ref,
|
|
) async {
|
|
final service = ref.watch(exerciseServiceProvider);
|
|
return service.getCurrentPlan().timeout(const Duration(seconds: 8));
|
|
});
|
|
|
|
typedef TodayHealthSnapshot = ({
|
|
Map<String, dynamic> health,
|
|
List<Map<String, dynamic>> reminders,
|
|
Map<String, dynamic>? exercisePlan,
|
|
});
|
|
|
|
/// 首页今日健康一次性快照。依赖项即使先后返回,也只在全部完成后整体更新。
|
|
final todayHealthSnapshotProvider = FutureProvider<TodayHealthSnapshot>((
|
|
ref,
|
|
) async {
|
|
final values = await Future.wait<dynamic>([
|
|
ref.watch(latestHealthProvider.future),
|
|
ref.watch(medicationReminderProvider.future),
|
|
ref.watch(currentExercisePlanProvider.future),
|
|
]);
|
|
return (
|
|
health: values[0] as Map<String, dynamic>,
|
|
reminders: values[1] as List<Map<String, dynamic>>,
|
|
exercisePlan: values[2] as Map<String, dynamic>?,
|
|
);
|
|
});
|
|
|
|
/// 拍照/相册直接触发(无需跳转页面)
|
|
final cameraActionProvider = NotifierProvider<CameraActionNotifier, String?>(
|
|
CameraActionNotifier.new,
|
|
);
|
|
|
|
class CameraActionNotifier extends Notifier<String?> {
|
|
@override
|
|
String? build() => null;
|
|
void trigger(String action) => state = action;
|
|
void clear() => state = null;
|
|
}
|
|
|
|
/// 拍饮食动作触发(不用跳多余页面)
|
|
final dietActionProvider = NotifierProvider<DietActionNotifier, String?>(
|
|
DietActionNotifier.new,
|
|
);
|
|
|
|
class DietActionNotifier extends Notifier<String?> {
|
|
@override
|
|
String? build() => null;
|
|
void trigger(String action) => state = action;
|
|
void clear() => state = null;
|
|
}
|