You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App_New/lib/services/navigation_service.dart

45 lines
1.5 KiB
Dart

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