From 285287e5966e4198be3ce751c6113b5d69e2af14 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 4 May 2026 15:32:30 +0300 Subject: [PATCH] crashlytics fixes --- .../immediate_livecare_view_model.dart | 8 ++- lib/presentation/authentication/login.dart | 2 +- .../tele_consultation/zoom/call_screen.dart | 35 +++++++------ .../tele_consultation/zoom/video_view.dart | 51 ++++++++++++------- lib/widgets/common_bottom_sheet.dart | 11 +++- 5 files changed, 69 insertions(+), 38 deletions(-) diff --git a/lib/features/immediate_livecare/immediate_livecare_view_model.dart b/lib/features/immediate_livecare/immediate_livecare_view_model.dart index 1b1d1f9e..68ae6952 100644 --- a/lib/features/immediate_livecare/immediate_livecare_view_model.dart +++ b/lib/features/immediate_livecare/immediate_livecare_view_model.dart @@ -255,11 +255,15 @@ class ImmediateLiveCareViewModel extends ChangeNotifier { result.fold( (failure) async { - onError!(failure.message); + if (onError != null) { + onError(failure.message); + } }, (apiResponse) { if (apiResponse.messageStatus == 2) { - onError!(apiResponse.errorMessage ?? "Unknown error occurred"); + if (onError != null) { + onError(apiResponse.errorMessage ?? "Unknown error occurred"); + } // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); } else if (apiResponse.messageStatus == 1) { patientLiveCareHistoryList = apiResponse.data!; diff --git a/lib/presentation/authentication/login.dart b/lib/presentation/authentication/login.dart index ee240fd3..04111c8d 100644 --- a/lib/presentation/authentication/login.dart +++ b/lib/presentation/authentication/login.dart @@ -50,7 +50,7 @@ class LoginScreenState extends State { // Clear errors when leaving login screen // Use post frame callback to avoid calling notifyListeners during dispose WidgetsBinding.instance.addPostFrameCallback((_) { - final authVm = context.read(); + final authVm = getIt.get(); authVm.clearNationalIdError(); authVm.clearPhoneNumberError(); }); diff --git a/lib/presentation/tele_consultation/zoom/call_screen.dart b/lib/presentation/tele_consultation/zoom/call_screen.dart index 2d3e9dbf..82ae6332 100644 --- a/lib/presentation/tele_consultation/zoom/call_screen.dart +++ b/lib/presentation/tele_consultation/zoom/call_screen.dart @@ -17,6 +17,7 @@ import 'package:flutter_zoom_videosdk/native/zoom_videosdk_event_listener.dart'; import 'package:flutter_zoom_videosdk/native/zoom_videosdk_live_transcription_message_info.dart'; import 'package:flutter_zoom_videosdk/native/zoom_videosdk_share_action.dart'; import 'package:flutter_zoom_videosdk/native/zoom_videosdk_user.dart'; +import 'package:get_it/get_it.dart'; import 'package:hmg_patient_app_new/core/app_export.dart'; import 'package:hmg_patient_app_new/core/cache_consts.dart'; import 'package:hmg_patient_app_new/core/utils/jwt.dart'; @@ -26,6 +27,7 @@ import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart'; import 'package:hmg_patient_app_new/presentation/tele_consultation/zoom/video_view.dart'; import 'package:hmg_patient_app_new/services/livecare_permission_service.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/widgets/routes/custom_page_route.dart'; import 'package:image_picker/image_picker.dart'; @@ -326,12 +328,15 @@ class _CallScreenState extends State { // If no remote users remain, the other participant has left — end the session if (remoteUserList == null || remoteUserList.isEmpty) { await zoom.leaveSession(true); - Navigator.pushAndRemoveUntil( - context, - CustomPageRoute( - page: LandingNavigation(), - ), - (r) => false); + final navContext = GetIt.instance().navigatorKey.currentContext; + if (navContext != null && Navigator.canPop(navContext)) { + Navigator.pushAndRemoveUntil( + navContext, + CustomPageRoute( + page: LandingNavigation(), + ), + (r) => false); + } return; } @@ -522,15 +527,15 @@ class _CallScreenState extends State { ), ); if (errorType == Errors.SessionJoinFailed || errorType == Errors.SessionDisconnecting) { - Timer( - const Duration(milliseconds: 1000), - () => { - Navigator.popAndPushNamed( - context, - "Join", - arguments: JoinArguments(args.isJoin, sessionName.value, sessionPassword.value, args.displayName, args.sessionIdleTimeoutMins, args.role), - ), - }); + // Timer( + // const Duration(milliseconds: 1000), + // () { + // Navigator.popAndPushNamed( + // context, + // "Join", + // arguments: JoinArguments(args.isJoin, sessionName.value, sessionPassword.value, args.displayName, args.sessionIdleTimeoutMins, args.role), + // ); + // }); } }); diff --git a/lib/presentation/tele_consultation/zoom/video_view.dart b/lib/presentation/tele_consultation/zoom/video_view.dart index 4c1e0494..575d1c99 100644 --- a/lib/presentation/tele_consultation/zoom/video_view.dart +++ b/lib/presentation/tele_consultation/zoom/video_view.dart @@ -30,17 +30,26 @@ class VideoView extends FlutterZoomView.ZoomView { var isMounted = useIsMounted(); var zoom = ZoomVideoSdk(); var isSharing = useState(false); - user?.audioStatus?.isMuted().then((muted) => isMuted.value = muted); useEffect(() { - updateVideoStatus() { + updateVideoStatus() async { if (user == null) return; - Future.microtask(() async { + try { if (isMounted()) { isVideoOn.value = (await user!.videoStatus!.isOn()); isSharing.value = sharing; + + // Update initial audio status safely + if (user!.audioStatus != null) { + var muted = await user!.audioStatus!.isMuted(); + if (isMounted()) { + isMuted.value = muted; + } + } } - }); + } catch (e) { + // User might have left the session, ignore error + } } resetAudioStatus() { @@ -49,20 +58,26 @@ class VideoView extends FlutterZoomView.ZoomView { } updateAudioStatus() async { - if (!isMounted()) return; - var talking = await user?.audioStatus?.isTalking(); - var muted = await user?.audioStatus?.isMuted(); - isMuted.value = muted!; - isTalking.value = talking!; - if (talking) { - Timer( - const Duration(milliseconds: SHOW_TALKING_ICON_DURATION), - () => { - if (isMounted()) - { - isTalking.value = false, - } - }); + if (!isMounted() || user?.audioStatus == null) return; + try { + var talking = await user!.audioStatus!.isTalking(); + var muted = await user!.audioStatus!.isMuted(); + if (isMounted()) { + isMuted.value = muted; + isTalking.value = talking; + if (talking) { + Timer( + const Duration(milliseconds: SHOW_TALKING_ICON_DURATION), + () => { + if (isMounted()) + { + isTalking.value = false, + } + }); + } + } + } catch (e) { + // User might have left the session, ignore error } } diff --git a/lib/widgets/common_bottom_sheet.dart b/lib/widgets/common_bottom_sheet.dart index 7b485e75..c3e78a6a 100644 --- a/lib/widgets/common_bottom_sheet.dart +++ b/lib/widgets/common_bottom_sheet.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/app_export.dart'; +import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/core/utils/calender_utils_new.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; @@ -149,7 +150,10 @@ void showCommonBottomSheet(BuildContext context, builder: (BuildContext context) { if (isAutoDismiss) { Future.delayed(Duration(seconds: 2), () { - Navigator.of(context).pop(); + final navContext = getIt.get().navigatorKey.currentContext; + if (navContext != null && Navigator.canPop(navContext)) { + Navigator.of(navContext).pop(); + } if (callBackFunc != null) { callBackFunc(null); } @@ -265,7 +269,10 @@ void showCommonBottomSheetWithoutHeight( builder: (BuildContext context) { if (isAutoDismiss) { Future.delayed(Duration(seconds: 2), () { - Navigator.of(GetIt.instance().navigatorKey.currentContext!).pop(); + final navContext = GetIt.instance().navigatorKey.currentContext; + if (navContext != null && Navigator.canPop(navContext)) { + Navigator.of(navContext).pop(); + } if (callBackFunc != null) { callBackFunc(); }