import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; 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/extensions/route_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/services/navigation_service.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/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart'; import 'package:provider/provider.dart'; abstract class DialogService { Future showErrorBottomSheet({required String message, Function()? onOkPressed}); Future showExceptionBottomSheet({required String message, required Function() onOkPressed, Function()? onCancelPressed}); Future showCommonBottomSheetWithoutH({String? label, required String message, required Function() onOkPressed, Function()? onCancelPressed}); Future showPhoneNumberPickerSheet({String? label, String? message, required Function() onSMSPress, required Function() onWhatsappPress}); // TODO : Need to be Fixed showPhoneNumberPickerSheet ( From Login ADn Signup Bottom Sheet Move Here } class DialogServiceImp implements DialogService { final NavigationService navigationService; DialogServiceImp({required this.navigationService}); @override Future showErrorBottomSheet({required String message, Function()? onOkPressed}) async { final context = navigationService.navigatorKey.currentContext; if (context == null) return; await showModalBottomSheet( context: context, isScrollControlled: false, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(16)), ), builder: (_) => _ErrorBottomSheet(message: message, onOkPressed: onOkPressed ?? () {}), ); } @override Future showExceptionBottomSheet({required String message, required Function() onOkPressed, Function()? onCancelPressed}) async { final context = navigationService.navigatorKey.currentContext; if (context == null) return; await showModalBottomSheet( context: context, isScrollControlled: false, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(16)), ), builder: (_) => ExceptionBottomSheet( message: message, showCancel: onCancelPressed != null ? true : false, onOkPressed: onOkPressed, onCancelPressed: () { if (onCancelPressed != null) { Navigator.of(context).pop(); } }, ), ); } @override Future showCommonBottomSheetWithoutH({String? label, required String message, required Function() onOkPressed, Function()? onCancelPressed}) async { final context = navigationService.navigatorKey.currentContext; if (context == null) return; showCommonBottomSheetWithoutHeight(context, title: label ?? "", child: exceptionBottomSheetWidget(context: context, message: message, onOkPressed: onOkPressed, onCancelPressed: onCancelPressed), callBackFunc: () { }); } @override Future showPhoneNumberPickerSheet({String? label, String? message, required Function() onSMSPress, required Function() onWhatsappPress}) async { final context = navigationService.navigatorKey.currentContext; if (context == null) return; showCommonBottomSheetWithoutHeight(context, title: label ?? "", child: showPhoneNumberPickerWidget(context: context, message: message, onSMSPress: onSMSPress, onWhatsappPress: onWhatsappPress), callBackFunc: () {}); } } Widget exceptionBottomSheetWidget({required BuildContext context, required String message, required Function() onOkPressed, Function()? onCancelPressed}) { return Column( children: [ (message ?? "").toText16(isBold: false, color: AppColors.textColor), SizedBox(height: 10.h), SizedBox(height: 24.h), if (onOkPressed != null && onCancelPressed != null) Row( children: [ Expanded( child: CustomButton( text: LocaleKeys.cancel.tr(), onPressed: () { Navigator.of(context).pop(); }, backgroundColor: AppColors.secondaryLightRedColor, borderColor: AppColors.secondaryLightRedColor, textColor: AppColors.primaryRedColor, icon: AppAssets.cancel, iconColor: AppColors.primaryRedColor, ), ), SizedBox(width: 5.h), Expanded( child: CustomButton( text: onCancelPressed != null ? LocaleKeys.confirm.tr() : LocaleKeys.ok.tr(), onPressed: onOkPressed, backgroundColor: AppColors.bgGreenColor, borderColor: AppColors.bgGreenColor, textColor: Colors.white, icon: AppAssets.confirm, ), ), ], ), if (onOkPressed != null && onCancelPressed == null) Padding( padding: EdgeInsets.only(bottom: 10.h), child: CustomButton( text: LocaleKeys.ok.tr(), onPressed: (onOkPressed != null && onCancelPressed == null) ? () { Navigator.of(context).pop(); } : onOkPressed, backgroundColor: AppColors.primaryRedColor, borderColor: AppColors.primaryRedBorderColor, textColor: Colors.white, icon: AppAssets.confirm, ), ), ], ); } Widget showPhoneNumberPickerWidget({required BuildContext context, String? message, required Function() onSMSPress, required Function() onWhatsappPress}) { return StatefulBuilder(builder: (BuildContext context, StateSetter setModalState) { AuthenticationViewModel authViewModel = context.read(); return Column( children: [ (message ?? "").toText16(isBold: false, color: AppColors.textColor), SizedBox(height: 10.h), Padding( padding: EdgeInsets.only(bottom: 10.h), child: CustomButton( text: LocaleKeys.sendOTPSMS.tr(), onPressed: onSMSPress, backgroundColor: AppColors.primaryRedColor, borderColor: AppColors.primaryRedBorderColor, textColor: AppColors.whiteColor, icon: AppAssets.message, ), ), Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: EdgeInsets.symmetric(horizontal: 8.h), child: LocaleKeys.oR.tr().toText16(color: AppColors.textColor), ), ], ), Padding( padding: EdgeInsets.only(bottom: 10.h, top: 10.h), child: CustomButton( text: LocaleKeys.sendOTPWHATSAPP.tr(), onPressed: onWhatsappPress, backgroundColor: Colors.white, borderColor: AppColors.borderOnlyColor, textColor: AppColors.textColor, icon: AppAssets.whatsapp, iconColor: null, ), ), ], ); //return Padding( // padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), // child: SingleChildScrollView( // child: GenericBottomSheet( // countryCode: authViewModel.selectedCountrySignup.countryCode, // initialPhoneNumber: "", // textController: authViewModel.phoneNumberController, // isEnableCountryDropdown: true, // onCountryChange: authViewModel.onCountryChange, // onChange: authViewModel.onPhoneNumberChange, // buttons: [ // // ], // ), // ), // ); }); } 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(); }), ), ], ), ); } }