medora-provider/lib/data/services/navigation_service.dart

73 lines
2.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:medora/data/models/telemed_user.dart';
import 'package:medora/data/services/data_service.dart';
import 'package:medora/data/services/doctor_profile_service.dart';
import 'package:medora/route/route_names.dart';
class NavigationService {
static Future<void> handleUserNavigation(BuildContext context) async {
try {
final TelemedUser? userProfile = await DataService.getProfile();
if (userProfile == null) {
if (context.mounted) {
Navigator.pushReplacementNamed(context, RouteNames.launch);
}
return;
}
if (userProfile.role.toLowerCase() != 'doctor') {
if (context.mounted) {
Navigator.pushReplacementNamed(context, RouteNames.launch);
return;
}
}
if (context.mounted) {
await handleDoctorNavigation(context);
}
} catch (e) {
print('Error in handleUserNavigation: $e');
if (context.mounted) {
Navigator.pushReplacementNamed(context, RouteNames.launch);
}
}
}
static Future<void> handleDoctorNavigation(BuildContext context) async {
final doctorProfile = await DoctorProfileService.getDoctorProfile();
if (context.mounted) {
if (doctorProfile != null) {
Navigator.pushReplacementNamed(
context,
RouteNames.doctorDashbordScreen,
);
} else {
Navigator.pushReplacementNamed(context, RouteNames.profileUpload);
}
}
}
// static Future<void> handlePatientNavigation(BuildContext context) async {
// try {
// final patientProfile = await PatientProfileService.getPatientProfile();
// if (context.mounted) {
// if (patientProfile != null) {
// Navigator.pushReplacementNamed(
// context, RouteNames.patientDashboardScreen);
// } else {
// Navigator.pushReplacementNamed(
// context, RouteNames.patientLandingScreen);
// }
// }
// } catch (e) {
// print('Error in handlePatientNavigation: $e');
// if (context.mounted) {
// Navigator.pushReplacementNamed(
// context, RouteNames.patientLandingScreen);
// }
// }
// }
}