import 'package:flutter/material.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/features/authentication/widgets/otp_verification_screen.dart'; import 'package:hmg_patient_app_new/routes/app_routes.dart'; class NavigationService { final GlobalKey navigatorKey = GlobalKey(); BuildContext? get context => navigatorKey.currentContext; Future push(Route route) { return navigatorKey.currentState!.push(route); } void pop([T? result]) { navigatorKey.currentState!.pop(result); } void popUntilNamed(String routeName) { navigatorKey.currentState?.popUntil(ModalRoute.withName(routeName)); } void replaceAllRoutesAndNavigateToLanding() { AppState appState = getIt.get(); appState.isAuthenticated = false; navigatorKey.currentState?.pushNamedAndRemoveUntil( AppRoutes.landingScreen, (Route route) => false, ); } void pushAndReplace(String routeName) { navigatorKey.currentState?.pushReplacementNamed(routeName); } Future pushToOtpScreen({required String phoneNumber, required Function(int code) checkActivationCode, required Function(String phoneNumber) onResendOTPPressed}) { return navigatorKey.currentState!.push( MaterialPageRoute(builder: (_) => OTPVerificationScreen(phoneNumber: phoneNumber, checkActivationCode: checkActivationCode, onResendOTPPressed: onResendOTPPressed)), ); } Future pushPage({ required Widget page, bool fullscreenDialog = false, bool maintainState = true, }) { return navigatorKey.currentState!.push( MaterialPageRoute( builder: (_) => page, fullscreenDialog: fullscreenDialog, maintainState: maintainState, ), ); } }