Merge branch 'master' into haroon_dev

pull/355/head
haroon amjad 1 week ago
commit 5e7b1b1ffd

@ -370,6 +370,7 @@ class MyApp extends StatelessWidget {
darkTheme: AppTheme.getDarkTheme(isArabic), darkTheme: AppTheme.getDarkTheme(isArabic),
themeMode: profileVm.isDarkMode ? ThemeMode.dark : ThemeMode.light, themeMode: profileVm.isDarkMode ? ThemeMode.dark : ThemeMode.light,
navigatorKey: getIt.get<NavigationService>().navigatorKey, navigatorKey: getIt.get<NavigationService>().navigatorKey,
navigatorObservers: [getIt.get<NavigationService>().routeObserver],
); );
}, },
); );

@ -16,6 +16,7 @@ import 'package:hmg_patient_app_new/features/authentication/authentication_view_
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/authentication/login.dart'; import 'package:hmg_patient_app_new/presentation/authentication/login.dart';
import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart'; import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart';
import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/appbar/app_bar_widget.dart'; import 'package:hmg_patient_app_new/widgets/appbar/app_bar_widget.dart';
import 'package:hmg_patient_app_new/widgets/bottomsheet/generic_bottom_sheet.dart'; import 'package:hmg_patient_app_new/widgets/bottomsheet/generic_bottom_sheet.dart';
@ -30,11 +31,24 @@ class SavedLogin extends StatefulWidget {
_SavedLogin createState() => _SavedLogin(); _SavedLogin createState() => _SavedLogin();
} }
class _SavedLogin extends State<SavedLogin> { class _SavedLogin extends State<SavedLogin> with RouteAware {
LoginTypeEnum loginType = LoginTypeEnum.sms; LoginTypeEnum loginType = LoginTypeEnum.sms;
late AuthenticationViewModel authVm; late AuthenticationViewModel authVm;
late AppState appState; late AppState appState;
bool? isOther; bool? isOther;
PageRoute<dynamic>? _pageRoute;
void _assignSavedLoginData() {
authVm.phoneNumberController.text = appState.getSelectDeviceByImeiRespModelElement!.mobile!.startsWith("0")
? appState.getSelectDeviceByImeiRespModelElement!.mobile!.replaceFirst("0", "")
: appState.getSelectDeviceByImeiRespModelElement!.mobile!;
authVm.nationalIdController.text = appState.getSelectDeviceByImeiRespModelElement!.identificationNo!;
if (isOther == true) {
authVm.phoneNumberController.text = appState.getSelectDeviceByImeiRespModelElement!.mobile!;
authVm.selectedCountrySignup = CountryEnum.others;
}
}
@override @override
void initState() { void initState() {
@ -43,19 +57,10 @@ class _SavedLogin extends State<SavedLogin> {
appState = getIt.get<AppState>(); appState = getIt.get<AppState>();
loginType = LoginTypeExtension.fromValue(appState.getSelectDeviceByImeiRespModelElement!.logInType!)!; loginType = LoginTypeExtension.fromValue(appState.getSelectDeviceByImeiRespModelElement!.logInType!)!;
authVm.phoneNumberController.text = appState.getSelectDeviceByImeiRespModelElement!.mobile!.startsWith("0")
? appState.getSelectDeviceByImeiRespModelElement!.mobile!.replaceFirst("0", "")
: appState.getSelectDeviceByImeiRespModelElement!.mobile!;
authVm.nationalIdController.text = appState.getSelectDeviceByImeiRespModelElement!.identificationNo!;
// Check if this is an "Others" country user // Check if this is an "Others" country user
isOther = appState.getSelectDeviceByImeiRespModelElement!.isOther == true; isOther = appState.getSelectDeviceByImeiRespModelElement!.isOther == true;
// Set country to Others if isOther flag is true - this ensures _Others APIs are called _assignSavedLoginData();
if (isOther!) {
authVm.phoneNumberController.text = appState.getSelectDeviceByImeiRespModelElement!.mobile!;
authVm.selectedCountrySignup = CountryEnum.others;
}
if (loginType == LoginTypeEnum.fingerprint || loginType == LoginTypeEnum.face) { if (loginType == LoginTypeEnum.fingerprint || loginType == LoginTypeEnum.face) {
authVm.loginWithFingerPrintFace(() {}); authVm.loginWithFingerPrintFace(() {});
@ -63,6 +68,30 @@ class _SavedLogin extends State<SavedLogin> {
super.initState(); super.initState();
} }
@override
void didChangeDependencies() {
super.didChangeDependencies();
final route = ModalRoute.of(context);
if (route is PageRoute && route != _pageRoute) {
if (_pageRoute != null) {
getIt.get<NavigationService>().routeObserver.unsubscribe(this);
}
_pageRoute = route;
getIt.get<NavigationService>().routeObserver.subscribe(this, route);
}
}
@override
void didPopNext() {
_assignSavedLoginData();
}
@override
void dispose() {
getIt.get<NavigationService>().routeObserver.unsubscribe(this);
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(

@ -6,6 +6,7 @@ import 'package:hmg_patient_app_new/routes/app_routes.dart';
class NavigationService { class NavigationService {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
final RouteObserver<PageRoute<dynamic>> routeObserver = RouteObserver<PageRoute<dynamic>>();
BuildContext? get context => navigatorKey.currentContext; BuildContext? get context => navigatorKey.currentContext;

Loading…
Cancel
Save