Merge branch 'master' into haroon_dev

# Conflicts:
#	ios/Runner.xcodeproj/project.pbxproj
#	lib/presentation/medical_file/medical_file_page.dart
pull/67/head
haroon amjad 4 weeks ago
commit 1d22e53f63

@ -9,7 +9,6 @@ import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/routes/app_routes.dart'; import 'package:hmg_patient_app_new/routes/app_routes.dart';
import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart'; import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart'; import 'package:hmg_patient_app_new/services/navigation_service.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
@ -80,14 +79,11 @@ abstract class ApiClient {
class ApiClientImp implements ApiClient { class ApiClientImp implements ApiClient {
final _analytics = getIt<GAnalytics>(); final _analytics = getIt<GAnalytics>();
final LoggerService _loggerService;
final AppState _appState; final AppState _appState;
ApiClientImp({ ApiClientImp({
required LoggerService loggerService,
required AppState appState, required AppState appState,
}) : _appState = appState, }) : _appState = appState;
_loggerService = loggerService;
@override @override
post( post(
@ -200,7 +196,6 @@ class ApiClientImp implements ApiClient {
final int statusCode = response.statusCode; final int statusCode = response.statusCode;
log("response.body: ${response.body}"); log("response.body: ${response.body}");
if (statusCode < 200 || statusCode >= 400) { if (statusCode < 200 || statusCode >= 400) {
var parsed = json.decode(utf8.decode(response.bodyBytes));
onFailure('Error While Fetching data', statusCode, failureType: StatusCodeFailure("Error While Fetching data")); onFailure('Error While Fetching data', statusCode, failureType: StatusCodeFailure("Error While Fetching data"));
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode); logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
} else { } else {
@ -218,6 +213,7 @@ class ApiClientImp implements ApiClient {
} else { } else {
if (parsed['ErrorType'] == 4) { if (parsed['ErrorType'] == 4) {
//TODO : handle app update //TODO : handle app update
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode, failureType: AppUpdateFailure("parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']"));
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode); logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
} }
if (parsed['ErrorType'] == 2) { if (parsed['ErrorType'] == 2) {
@ -225,7 +221,7 @@ class ApiClientImp implements ApiClient {
onFailure( onFailure(
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
statusCode, statusCode,
failureType: MessageStatusFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']), failureType: UnAuthenticatedUserFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'] ?? "User is not Authenticated", url: url),
); );
// logApiEndpointError(endPoint, "session logged out", statusCode); // logApiEndpointError(endPoint, "session logged out", statusCode);
} }
@ -248,6 +244,12 @@ class ApiClientImp implements ApiClient {
} }
} else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) { } else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) {
onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus'], errorMessage: parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']); onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus'], errorMessage: parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']);
} else if (parsed['IsAuthenticated'] == false) {
onFailure(
"User is not Authenticated",
statusCode,
failureType: UnAuthenticatedUserFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'] ?? "User is not Authenticated", url: url),
);
} else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) { } else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) {
if (parsed['SameClinicApptList'] != null) { if (parsed['SameClinicApptList'] != null) {
onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus'], errorMessage: parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']); onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus'], errorMessage: parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']);
@ -277,7 +279,6 @@ class ApiClientImp implements ApiClient {
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode); logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
} }
} }
} else if (!parsed['IsAuthenticated']) {
} else { } else {
if (parsed['SameClinicApptList'] != null) { if (parsed['SameClinicApptList'] != null) {
onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus'], errorMessage: parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']); onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus'], errorMessage: parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']);

@ -79,7 +79,7 @@ class AppDependencies {
final sharedPreferences = await SharedPreferences.getInstance(); final sharedPreferences = await SharedPreferences.getInstance();
getIt.registerLazySingleton<CacheService>(() => CacheServiceImp(sharedPreferences: sharedPreferences, loggerService: getIt())); getIt.registerLazySingleton<CacheService>(() => CacheServiceImp(sharedPreferences: sharedPreferences, loggerService: getIt()));
getIt.registerLazySingleton<ApiClient>(() => ApiClientImp(loggerService: getIt(), appState: getIt())); getIt.registerLazySingleton<ApiClient>(() => ApiClientImp(appState: getIt()));
// Repositories // Repositories
getIt.registerLazySingleton<CommonRepo>(() => CommonRepoImp(loggerService: getIt())); getIt.registerLazySingleton<CommonRepo>(() => CommonRepoImp(loggerService: getIt()));
@ -129,11 +129,7 @@ class AppDependencies {
); );
getIt.registerLazySingleton<MyAppointmentsViewModel>( getIt.registerLazySingleton<MyAppointmentsViewModel>(
() => MyAppointmentsViewModel( () => MyAppointmentsViewModel(myAppointmentsRepo: getIt(), errorHandlerService: getIt(), appState: getIt()),
myAppointmentsRepo: getIt(),
errorHandlerService: getIt(),
appState: getIt()
),
); );
getIt.registerLazySingleton<PayfortViewModel>( getIt.registerLazySingleton<PayfortViewModel>(
@ -158,13 +154,7 @@ class AppDependencies {
); );
getIt.registerLazySingleton<BookAppointmentsViewModel>( getIt.registerLazySingleton<BookAppointmentsViewModel>(
() => BookAppointmentsViewModel( () => BookAppointmentsViewModel(bookAppointmentsRepo: getIt(), errorHandlerService: getIt(), navigationService: getIt(), myAppointmentsViewModel: getIt(), locationUtils: getIt()),
bookAppointmentsRepo: getIt(),
errorHandlerService: getIt(),
navigationService: getIt(),
myAppointmentsViewModel: getIt(),
locationUtils: getIt()
),
); );
getIt.registerLazySingleton<ImmediateLiveCareViewModel>( getIt.registerLazySingleton<ImmediateLiveCareViewModel>(

@ -7,7 +7,9 @@ abstract class Failure extends Equatable implements Exception {
} }
class ServerFailure extends Failure { class ServerFailure extends Failure {
const ServerFailure(super.message); final String url;
const ServerFailure(super.message, {this.url = ""});
@override @override
List<Object?> get props => [message]; List<Object?> get props => [message];
@ -27,6 +29,13 @@ class MessageStatusFailure extends Failure {
List<Object?> get props => [message]; List<Object?> get props => [message];
} }
class AppUpdateFailure extends Failure {
const AppUpdateFailure(super.message);
@override
List<Object?> get props => [message];
}
class StatusCodeFailure extends Failure { class StatusCodeFailure extends Failure {
const StatusCodeFailure(super.message); const StatusCodeFailure(super.message);
@ -34,6 +43,15 @@ class StatusCodeFailure extends Failure {
List<Object?> get props => [message]; List<Object?> get props => [message];
} }
class UnAuthenticatedUserFailure extends Failure {
final String url;
const UnAuthenticatedUserFailure(super.message, {this.url = ""});
@override
List<Object?> get props => [message];
}
class ConnectivityFailure extends Failure { class ConnectivityFailure extends Failure {
const ConnectivityFailure(super.message); const ConnectivityFailure(super.message);
@ -56,7 +74,9 @@ class DataParsingFailure extends Failure {
} }
class UnknownFailure extends Failure { class UnknownFailure extends Failure {
const UnknownFailure(super.message); final String url;
const UnknownFailure(super.message, {this.url = ""});
@override @override
List<Object?> get props => [message]; List<Object?> get props => [message];

@ -1,16 +1,16 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:developer'; import 'dart:developer';
import 'dart:io'; import 'dart:io';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:hijri_gregorian_calendar/hijri_gregorian_calendar.dart'; import 'package:hijri_gregorian_calendar/hijri_gregorian_calendar.dart';
import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/cache_consts.dart'; import 'package:hmg_patient_app_new/core/cache_consts.dart';
import 'package:hmg_patient_app_new/core/common_models/nationality_country_model.dart'; import 'package:hmg_patient_app_new/core/common_models/nationality_country_model.dart';
import 'package:hmg_patient_app_new/core/common_models/privilege/HMCProjectListModel.dart'; import 'package:hmg_patient_app_new/core/common_models/privilege/HMCProjectListModel.dart';
import 'package:hmg_patient_app_new/core/common_models/privilege/PrivilegeModel.dart';
import 'package:hmg_patient_app_new/core/common_models/privilege/ProjectDetailListModel.dart'; import 'package:hmg_patient_app_new/core/common_models/privilege/ProjectDetailListModel.dart';
import 'package:hmg_patient_app_new/core/common_models/privilege/VidaPlusProjectListModel.dart'; import 'package:hmg_patient_app_new/core/common_models/privilege/VidaPlusProjectListModel.dart';
import 'package:hmg_patient_app_new/core/enums.dart'; import 'package:hmg_patient_app_new/core/enums.dart';
@ -18,7 +18,6 @@ import 'package:hmg_patient_app_new/core/utils/loading_utils.dart';
import 'package:hmg_patient_app_new/core/utils/request_utils.dart'; import 'package:hmg_patient_app_new/core/utils/request_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/core/utils/validation_utils.dart'; import 'package:hmg_patient_app_new/core/utils/validation_utils.dart';
import 'package:hmg_patient_app_new/extensions/context_extensions.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/features/authentication/authentication_repo.dart'; import 'package:hmg_patient_app_new/features/authentication/authentication_repo.dart';
import 'package:hmg_patient_app_new/features/authentication/models/request_models/check_activation_code_register_request_model.dart'; import 'package:hmg_patient_app_new/features/authentication/models/request_models/check_activation_code_register_request_model.dart';
@ -37,7 +36,6 @@ import 'package:hmg_patient_app_new/services/error_handler_service.dart';
import 'package:hmg_patient_app_new/services/localauth_service.dart'; import 'package:hmg_patient_app_new/services/localauth_service.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart'; import 'package:hmg_patient_app_new/services/navigation_service.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart'; import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
import 'package:hmg_patient_app_new/widgets/bottomsheet/exception_bottom_sheet.dart';
import 'package:sms_otp_auto_verify/sms_otp_auto_verify.dart'; import 'package:sms_otp_auto_verify/sms_otp_auto_verify.dart';
import 'models/request_models/get_user_mobile_device_data.dart'; import 'models/request_models/get_user_mobile_device_data.dart';

@ -1,15 +1,11 @@
import 'dart:math';
import 'package:dartz/dartz.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/common_models/data_points.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/lab/history/lab_history_viewmodel.dart';
import 'package:hmg_patient_app_new/features/lab/lab_range_view_model.dart' show LabRangeViewModel; import 'package:hmg_patient_app_new/features/lab/lab_range_view_model.dart' show LabRangeViewModel;
import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart'; import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart';
import 'package:hmg_patient_app_new/features/lab/models/resp_models/lab_result.dart'; import 'package:hmg_patient_app_new/features/lab/models/resp_models/lab_result.dart';
@ -22,8 +18,6 @@ import 'package:provider/provider.dart' show Consumer, Provider;
import '../../../widgets/common_bottom_sheet.dart' import '../../../widgets/common_bottom_sheet.dart'
show showCommonBottomSheetWithoutHeight; show showCommonBottomSheetWithoutHeight;
import '../../book_appointment/widgets/appointment_calendar.dart'
show AppointmentCalendar;
class LabResultDetails extends StatelessWidget { class LabResultDetails extends StatelessWidget {
final LabResult recentLabResult; final LabResult recentLabResult;

@ -38,6 +38,8 @@ import 'package:hmg_patient_app_new/presentation/medical_file/vaccine_list_page.
import 'package:hmg_patient_app_new/presentation/medical_file/widgets/lab_rad_card.dart'; import 'package:hmg_patient_app_new/presentation/medical_file/widgets/lab_rad_card.dart';
import 'package:hmg_patient_app_new/presentation/medical_file/widgets/medical_file_card.dart'; import 'package:hmg_patient_app_new/presentation/medical_file/widgets/medical_file_card.dart';
import 'package:hmg_patient_app_new/presentation/medical_file/widgets/patient_sick_leave_card.dart'; import 'package:hmg_patient_app_new/presentation/medical_file/widgets/patient_sick_leave_card.dart';
import 'package:hmg_patient_app_new/presentation/my_family/my_family.dart';
import 'package:hmg_patient_app_new/presentation/my_family/widget/my_family_sheet.dart';
import 'package:hmg_patient_app_new/presentation/prescriptions/prescriptions_list_page.dart'; import 'package:hmg_patient_app_new/presentation/prescriptions/prescriptions_list_page.dart';
import 'package:hmg_patient_app_new/services/navigation_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/theme/colors.dart';

@ -1,11 +1,9 @@
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hmg_patient_app_new/core/app_assets.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/app_export.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/enums.dart'; import 'package:hmg_patient_app_new/core/enums.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/core/utils/validation_utils.dart'; import 'package:hmg_patient_app_new/core/utils/validation_utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
@ -13,7 +11,6 @@ import 'package:hmg_patient_app_new/features/authentication/authentication_view_
import 'package:hmg_patient_app_new/features/medical_file/models/family_file_response_model.dart'; import 'package:hmg_patient_app_new/features/medical_file/models/family_file_response_model.dart';
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/my_family/widget/family_cards.dart'; import 'package:hmg_patient_app_new/presentation/my_family/widget/family_cards.dart';
import 'package:hmg_patient_app_new/services/dialog_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/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
@ -27,10 +24,10 @@ class FamilyMedicalScreen extends StatefulWidget {
final Function(FamilyFileResponseModelLists) onSelect; final Function(FamilyFileResponseModelLists) onSelect;
const FamilyMedicalScreen({ const FamilyMedicalScreen({
Key? key, super.key,
required this.profiles, required this.profiles,
required this.onSelect, required this.onSelect,
}) : super(key: key); });
@override @override
State<FamilyMedicalScreen> createState() => _FamilyMedicalScreenState(); State<FamilyMedicalScreen> createState() => _FamilyMedicalScreenState();
@ -85,9 +82,9 @@ class _FamilyMedicalScreenState extends State<FamilyMedicalScreen> {
); );
} }
void showModelSheet() { Future<void> showModelSheet() async {
AuthenticationViewModel authVm = getIt.get<AuthenticationViewModel>(); AuthenticationViewModel authVm = getIt.get<AuthenticationViewModel>();
return showCommonBottomSheetWithoutHeight(context, return await showCommonBottomSheetWithoutHeight(context,
title: "Add Family Member", title: "Add Family Member",
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,

@ -43,9 +43,7 @@ class _FamilyCardsState extends State<FamilyCards> {
), ),
itemBuilder: (context, index) { itemBuilder: (context, index) {
final profile = widget.profiles[index]; final profile = widget.profiles[index];
final isActive = (profile.responseId == appState final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId);
.getAuthenticatedUser()
?.patientId);
return Container( return Container(
padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.h), padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.h),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24), decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24),

@ -1,15 +1,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/features/medical_file/models/family_file_response_model.dart'; import 'package:hmg_patient_app_new/features/medical_file/models/family_file_response_model.dart';
import 'package:hmg_patient_app_new/presentation/my_family/my_Family.dart';
import 'package:hmg_patient_app_new/presentation/my_family/widget/family_cards.dart'; import 'package:hmg_patient_app_new/presentation/my_family/widget/family_cards.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/common_bottom_sheet.dart'; import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
class MyFamilySheet { class MyFamilySheet {
static void show(BuildContext context, List<FamilyFileResponseModelLists> familyLists, Function(FamilyFileResponseModelLists) onSelect) { static Future<void> show(BuildContext context, List<FamilyFileResponseModelLists> familyLists, Function(FamilyFileResponseModelLists) onSelect) async {
return showCommonBottomSheetWithoutHeight( return await showCommonBottomSheetWithoutHeight(
context, context,
titleWidget: Column( titleWidget: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,

@ -4,18 +4,15 @@ import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/extensions/route_extensions.dart'; import 'package:hmg_patient_app_new/extensions/route_extensions.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/authentication/authentication_view_model.dart';
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/services/navigation_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/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/bottomsheet/exception_bottom_sheet.dart'; import 'package:hmg_patient_app_new/widgets/bottomsheet/exception_bottom_sheet.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart'; import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
import 'package:provider/provider.dart';
abstract class DialogService { abstract class DialogService {
Future<void> showErrorBottomSheet({required String message, Function()? onOkPressed}); Future<void> showErrorBottomSheet({String title = "", required String message, Function()? onOkPressed, Function()? onCancelPressed});
Future<void> showExceptionBottomSheet({required String message, required Function() onOkPressed, Function()? onCancelPressed}); Future<void> showExceptionBottomSheet({required String message, required Function() onOkPressed, Function()? onCancelPressed});
@ -28,21 +25,40 @@ abstract class DialogService {
class DialogServiceImp implements DialogService { class DialogServiceImp implements DialogService {
final NavigationService navigationService; final NavigationService navigationService;
bool _isErrorSheetShowing = false;
DialogServiceImp({required this.navigationService}); DialogServiceImp({required this.navigationService});
@override @override
Future<void> showErrorBottomSheet({required String message, Function()? onOkPressed}) async { Future<void> showErrorBottomSheet({String title = "", required String message, Function()? onOkPressed, Function()? onCancelPressed}) async {
if (_isErrorSheetShowing) return;
final context = navigationService.navigatorKey.currentContext; final context = navigationService.navigatorKey.currentContext;
if (context == null) return; if (context == null) return;
_isErrorSheetShowing = true;
await showModalBottomSheet( await showModalBottomSheet(
context: context, context: context,
isScrollControlled: false, isScrollControlled: false,
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)), borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
), ),
builder: (_) => _ErrorBottomSheet(message: message, onOkPressed: onOkPressed ?? () {}), builder: (_) => ExceptionBottomSheet(
// title: title,
message: message,
showCancel: onCancelPressed != null ? true : false,
onOkPressed: () {
if (onOkPressed != null) {
onOkPressed();
}
},
onCancelPressed: () {
if (onCancelPressed != null) {
context.pop();
}
},
),
); );
_isErrorSheetShowing = false;
} }
@override @override
@ -73,9 +89,8 @@ class DialogServiceImp implements DialogService {
Future<void> showCommonBottomSheetWithoutH({String? label, required String message, required Function() onOkPressed, Function()? onCancelPressed}) async { Future<void> showCommonBottomSheetWithoutH({String? label, required String message, required Function() onOkPressed, Function()? onCancelPressed}) async {
final context = navigationService.navigatorKey.currentContext; final context = navigationService.navigatorKey.currentContext;
if (context == null) return; if (context == null) return;
showCommonBottomSheetWithoutHeight(context, title: label ?? "", child: exceptionBottomSheetWidget(context: context, message: message, onOkPressed: onOkPressed, onCancelPressed: onCancelPressed), showCommonBottomSheetWithoutHeight(context,
callBackFunc: () { title: label ?? "", child: exceptionBottomSheetWidget(context: context, message: message, onOkPressed: onOkPressed, onCancelPressed: onCancelPressed), callBackFunc: () {});
});
} }
@override @override
@ -90,10 +105,10 @@ class DialogServiceImp implements DialogService {
Widget exceptionBottomSheetWidget({required BuildContext context, required String message, required Function() onOkPressed, Function()? onCancelPressed}) { Widget exceptionBottomSheetWidget({required BuildContext context, required String message, required Function() onOkPressed, Function()? onCancelPressed}) {
return Column( return Column(
children: [ children: [
(message ?? "").toText16(isBold: false, color: AppColors.textColor), (message).toText16(isBold: false, color: AppColors.textColor),
SizedBox(height: 10.h), SizedBox(height: 10.h),
SizedBox(height: 24.h), SizedBox(height: 24.h),
if (onOkPressed != null && onCancelPressed != null) if (onCancelPressed != null)
Row( Row(
children: [ children: [
Expanded( Expanded(
@ -112,7 +127,7 @@ Widget exceptionBottomSheetWidget({required BuildContext context, required Strin
SizedBox(width: 5.h), SizedBox(width: 5.h),
Expanded( Expanded(
child: CustomButton( child: CustomButton(
text: onCancelPressed != null ? LocaleKeys.confirm.tr() : LocaleKeys.ok.tr(), text: LocaleKeys.confirm.tr(),
onPressed: onOkPressed, onPressed: onOkPressed,
backgroundColor: AppColors.bgGreenColor, backgroundColor: AppColors.bgGreenColor,
borderColor: AppColors.bgGreenColor, borderColor: AppColors.bgGreenColor,
@ -122,14 +137,14 @@ Widget exceptionBottomSheetWidget({required BuildContext context, required Strin
), ),
], ],
), ),
if (onOkPressed != null && onCancelPressed == null) if (onCancelPressed == null)
Padding( Padding(
padding: EdgeInsets.only(bottom: 10.h), padding: EdgeInsets.only(bottom: 10.h),
child: CustomButton( child: CustomButton(
text: LocaleKeys.ok.tr(), text: LocaleKeys.ok.tr(),
onPressed: (onOkPressed != null && onCancelPressed == null) onPressed: (onCancelPressed == null)
? () { ? () {
Navigator.of(context).pop(); context.pop();
} }
: onOkPressed, : onOkPressed,
backgroundColor: AppColors.primaryRedColor, backgroundColor: AppColors.primaryRedColor,
@ -144,7 +159,6 @@ Widget exceptionBottomSheetWidget({required BuildContext context, required Strin
Widget showPhoneNumberPickerWidget({required BuildContext context, String? message, required Function() onSMSPress, required Function() onWhatsappPress}) { Widget showPhoneNumberPickerWidget({required BuildContext context, String? message, required Function() onSMSPress, required Function() onWhatsappPress}) {
return StatefulBuilder(builder: (BuildContext context, StateSetter setModalState) { return StatefulBuilder(builder: (BuildContext context, StateSetter setModalState) {
AuthenticationViewModel authViewModel = context.read<AuthenticationViewModel>();
return Column( return Column(
children: [ children: [
(message ?? "").toText16(isBold: false, color: AppColors.textColor), (message ?? "").toText16(isBold: false, color: AppColors.textColor),
@ -202,56 +216,3 @@ Widget showPhoneNumberPickerWidget({required BuildContext context, String? messa
// ); // );
}); });
} }
class _ErrorBottomSheet extends StatelessWidget {
final String message;
final Function()? onOkPressed;
const _ErrorBottomSheet({required this.message, this.onOkPressed});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.error_outline, color: Colors.red, size: 40),
const SizedBox(height: 12),
Text(
"Error",
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
message,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
if (onOkPressed != null) {
onOkPressed!();
} else {
context.pop();
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text("OK", style: TextStyle(color: Colors.white)).onPress(() {
Navigator.of(context).pop();
}),
),
],
),
);
}
}

@ -3,7 +3,6 @@ import 'dart:io';
import 'package:hmg_patient_app_new/core/exceptions/api_exception.dart'; import 'package:hmg_patient_app_new/core/exceptions/api_exception.dart';
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart'; import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
import 'package:hmg_patient_app_new/core/utils/loading_utils.dart'; import 'package:hmg_patient_app_new/core/utils/loading_utils.dart';
import 'package:hmg_patient_app_new/extensions/route_extensions.dart';
import 'package:hmg_patient_app_new/services/dialog_service.dart'; import 'package:hmg_patient_app_new/services/dialog_service.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart'; import 'package:hmg_patient_app_new/services/logger_service.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart'; import 'package:hmg_patient_app_new/services/navigation_service.dart';
@ -28,46 +27,54 @@ class ErrorHandlerServiceImp implements ErrorHandlerService {
if (failure is APIException) { if (failure is APIException) {
loggerService.errorLogs("API Exception: ${failure.message}"); loggerService.errorLogs("API Exception: ${failure.message}");
} else if (failure is ServerFailure) { } else if (failure is ServerFailure) {
loggerService.errorLogs("Server Failure: ${failure.message}"); loggerService.errorLogs("URL: ${failure.url} \n Server Failure: ${failure.message}");
await _showDialog(failure); await _showDialog(failure, title: "Server Failure");
} else if (failure is DataParsingFailure) { } else if (failure is DataParsingFailure) {
loggerService.errorLogs("Data Parsing Failure: ${failure.message}"); loggerService.errorLogs("Data Parsing Failure: ${failure.message}");
await _showDialog(failure, title: "Data Error"); await _showDialog(failure, title: "Data Error");
} else if (failure is StatusCodeFailure) { } else if (failure is StatusCodeFailure) {
loggerService.errorLogs("StatusCode Failure: ${failure.message}"); loggerService.errorLogs("StatusCode Failure: ${failure.message}");
await _showDialog(failure, title: "Status Code Failure Error"); await _showDialog(failure, title: "StatusCodeFailure");
} else if (failure is ConnectivityFailure) {
loggerService.errorLogs("ConnectivityFailure : ${failure.message}");
await _showDialog(failure, title: "ConnectivityFailure ", onOkPressed: () {});
} else if (failure is UnAuthenticatedUserFailure) {
loggerService.errorLogs("URL: ${failure.url} \n UnAuthenticatedUser Failure: ${failure.message}");
await _showDialog(failure, title: "UnAuthenticatedUser Failure", onOkPressed: () => navigationService.replaceAllRoutesAndNavigateToLanding());
} else if (failure is AppUpdateFailure) {
loggerService.errorLogs("AppUpdateFailure : ${failure.message}");
await _showDialog(failure, title: "AppUpdateFailure Error", onOkPressed: () => navigationService.replaceAllRoutesAndNavigateToLanding());
} else if (failure is HttpException) { } else if (failure is HttpException) {
loggerService.errorLogs("Http Exception: ${failure.message}"); loggerService.errorLogs("Http Exception: ${failure.message}");
await _showDialog(failure, title: "Network Error"); await _showDialog(failure, title: "Network Error");
} else if (failure is UnknownFailure) { } else if (failure is UnknownFailure) {
loggerService.errorLogs("Unknown Failure: ${failure.message}"); loggerService.errorLogs("URL: ${failure.url} \n Unknown Failure: ${failure.message}");
await _showDialog(failure, title: "Unknown Error"); await _showDialog(failure, title: "Unknown Failure");
} else if (failure is InvalidCredentials) { } else if (failure is InvalidCredentials) {
loggerService.errorLogs("Invalid Credentials : ${failure.message}"); loggerService.errorLogs("Invalid Credentials : ${failure.message}");
await _showDialog(failure, title: "Unknown Error"); await _showDialog(failure, title: "Invalid Credentials ");
} else if (failure is UserIntimationFailure) { } else if (failure is UserIntimationFailure) {
if (onUnHandledFailure != null) { if (onUnHandledFailure != null) {
onUnHandledFailure(failure); onUnHandledFailure(failure);
} else { } else {
await _showDialog(failure, title: "Error", onOkPressed: onOkPressed); await _showDialog(failure, title: "UserIntimationFailure", onOkPressed: onOkPressed);
} }
} else if (failure is MessageStatusFailure) { } else if (failure is MessageStatusFailure) {
if (onMessageStatusFailure != null) { if (onMessageStatusFailure != null) {
onMessageStatusFailure(failure); onMessageStatusFailure(failure);
} else { } else {
await _showDialog(failure, title: "Error", onOkPressed: onOkPressed); await _showDialog(failure, title: "MessageStatusFailure", onOkPressed: onOkPressed);
} }
} else { } else {
loggerService.errorLogs("Unhandled failure type: $failure"); loggerService.errorLogs("Unhandled failure type: $failure");
await _showDialog(failure, title: "Error", onOkPressed: onOkPressed); await _showDialog(failure, title: "Unhandled Error", onOkPressed: onOkPressed);
} }
} }
Future<void> _showDialog(Failure failure, {String title = "Error", Function()? onOkPressed}) async { Future<void> _showDialog(Failure failure, {required String title, Function()? onOkPressed}) async {
if (LoadingUtils.isLoading) { if (LoadingUtils.isLoading) {
LoadingUtils.hideFullScreenLoader(); LoadingUtils.hideFullScreenLoader();
} }
await dialogService.showErrorBottomSheet(title: title, message: failure.message, onOkPressed: onOkPressed);
await dialogService.showErrorBottomSheet(message: failure.message, onOkPressed: onOkPressed);
} }
} }

@ -1,5 +1,8 @@
import 'package:flutter/material.dart'; 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/features/authentication/widgets/otp_verification_screen.dart';
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>();
@ -18,6 +21,15 @@ class NavigationService {
navigatorKey.currentState?.popUntil(ModalRoute.withName(routeName)); navigatorKey.currentState?.popUntil(ModalRoute.withName(routeName));
} }
void replaceAllRoutesAndNavigateToLanding() {
AppState appState = getIt.get<AppState>();
appState.isAuthenticated = false;
navigatorKey.currentState?.pushNamedAndRemoveUntil(
AppRoutes.landingScreen,
(Route<dynamic> route) => false,
);
}
void pushAndReplace(String routeName) { void pushAndReplace(String routeName) {
navigatorKey.currentState?.pushReplacementNamed(routeName); navigatorKey.currentState?.pushReplacementNamed(routeName);
} }

@ -11,13 +11,14 @@ import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
class ExceptionBottomSheet extends StatelessWidget { class ExceptionBottomSheet extends StatelessWidget {
String message; final String? title;
bool showOKButton; final String message;
bool showCancel; final bool showOKButton;
Function() onOkPressed; final bool showCancel;
Function()? onCancelPressed; final Function() onOkPressed;
final Function()? onCancelPressed;
ExceptionBottomSheet({Key? key, required this.message, this.showOKButton = true, this.showCancel = false, required this.onOkPressed, this.onCancelPressed}) : super(key: key); const ExceptionBottomSheet({super.key, this.title, required this.message, this.showOKButton = true, this.showCancel = false, required this.onOkPressed, this.onCancelPressed});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -44,7 +45,7 @@ class ExceptionBottomSheet extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
LocaleKeys.notice.tr().toText28(), (title ?? LocaleKeys.notice.tr()).toText28(),
InkWell( InkWell(
onTap: () { onTap: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
@ -54,7 +55,7 @@ class ExceptionBottomSheet extends StatelessWidget {
], ],
), ),
SizedBox(height: 10.h), SizedBox(height: 10.h),
(message ?? "").toText16(isBold: false, color: AppColors.textColor), (message).toText16(isBold: false, color: AppColors.textColor),
SizedBox(height: 10.h), SizedBox(height: 10.h),
SizedBox(height: 24.h), SizedBox(height: 24.h),
if (showOKButton && showCancel) if (showOKButton && showCancel)

@ -104,7 +104,7 @@ class ButtonSheetContent extends StatelessWidget {
} }
} }
void showCommonBottomSheetWithoutHeight( Future<void> showCommonBottomSheetWithoutHeight(
BuildContext context, { BuildContext context, {
required Widget child, required Widget child,
required VoidCallback callBackFunc, required VoidCallback callBackFunc,
@ -113,7 +113,7 @@ void showCommonBottomSheetWithoutHeight(
bool isFullScreen = true, bool isFullScreen = true,
bool isDismissible = true, bool isDismissible = true,
Widget? titleWidget, Widget? titleWidget,
}) { }) async {
showModalBottomSheet<String>( showModalBottomSheet<String>(
sheetAnimationStyle: AnimationStyle( sheetAnimationStyle: AnimationStyle(
duration: Duration(milliseconds: 500), // Custom animation duration duration: Duration(milliseconds: 500), // Custom animation duration

Loading…
Cancel
Save