medora-provider/lib/data/services/navigation_service.dart
DhanshCOSQ 66c3b2fb9c Patient registration complete with authentication flow fixed (#3)
Patient registration complete with authentication flow fixed

Co-authored-by: Benoy Bose <benoybose@gmail.com>
Co-authored-by: Jipson George <152465898+Jipson-cosq@users.noreply.github.com>
Reviewed-on: cosqnet/telemednet#3
Reviewed-by: Benoy Bose <benoybose@cosq.net>
Co-authored-by: DhanshCOSQ <dhanshas@cosq.net>
Co-committed-by: DhanshCOSQ <dhanshas@cosq.net>
2024-10-31 14:20:35 +00:00

76 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:telemednet/data/models/telemed_user.dart';
import 'package:telemednet/data/services/data_service.dart';
import 'package:telemednet/data/services/patient_registration_service.dart';
import 'package:telemednet/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;
}
switch (userProfile.role.toLowerCase()) {
case 'doctor':
if (context.mounted) {
handleDoctorNavigation(context);
}
break;
case 'patient':
if (context.mounted) {
handlePatientNavigation(context);
}
break;
default:
if (context.mounted) {
Navigator.pushReplacementNamed(context, RouteNames.launch);
}
}
} catch (e) {
print('Error in handleUserNavigation: $e');
if (context.mounted) {
Navigator.pushReplacementNamed(context, RouteNames.launch);
}
}
}
static Future<void> handleDoctorNavigation(BuildContext context) async {
if (context.mounted) {
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);
}
}
}
}