dev_aamir #244

Merged
khansultan1 merged 2 commits from dev_aamir into master 2 days ago

@ -25,7 +25,7 @@ class CalenderUtilsNew {
Future<void> getCalenders() async { Future<void> getCalenders() async {
CalendarPermissionStatus result = await DeviceCalendar.instance.hasPermissions(); CalendarPermissionStatus result = await DeviceCalendar.instance.hasPermissions();
if (result != CalendarPermissionStatus.granted) { if (result != CalendarPermissionStatus.granted) {
// await DeviceCalendar.instance.requestPermissions(); await DeviceCalendar.instance.requestPermissions();
showCommonBottomSheetWithoutHeight( showCommonBottomSheetWithoutHeight(
title: LocaleKeys.notice.tr(context: GetIt.instance<NavigationService>().navigatorKey.currentContext!), title: LocaleKeys.notice.tr(context: GetIt.instance<NavigationService>().navigatorKey.currentContext!),
GetIt.instance<NavigationService>().navigatorKey.currentContext!, GetIt.instance<NavigationService>().navigatorKey.currentContext!,

@ -80,8 +80,13 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
String _countdownText = ""; String _countdownText = "";
Function(void Function())? _modalSetState; // Callback for modal state updates Function(void Function())? _modalSetState; // Callback for modal state updates
// GlobalKey for BellAnimatedSwitch to control it programmatically
final GlobalKey<BellAnimatedSwitchState> _bellSwitchKey = GlobalKey<BellAnimatedSwitchState>();
@override @override
void initState() { void initState() {
super.initState();
scheduleMicrotask(() async { scheduleMicrotask(() async {
if (AppointmentType.isArrived(widget.patientAppointmentHistoryResponseModel)) { if (AppointmentType.isArrived(widget.patientAppointmentHistoryResponseModel)) {
myAppointmentsViewModel.getDoctorsRatingCheck( myAppointmentsViewModel.getDoctorsRatingCheck(
@ -102,12 +107,12 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
} }
}); });
// Initialize countdown timer for payment // Initialize countdown timer for payment after first frame to ensure context is available
if (widget.patientAppointmentHistoryResponseModel.nextAction == 15 || widget.patientAppointmentHistoryResponseModel.nextAction == 20) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
_startCountdownTimer(); _startCountdownTimer();
} }
});
super.initState();
} }
/// Checks if a reminder exists in the calendar for this appointment /// Checks if a reminder exists in the calendar for this appointment
@ -364,18 +369,13 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
onRescheduleTap: () async { onRescheduleTap: () async {
openDoctorScheduleCalendar(); openDoctorScheduleCalendar();
}, },
timerWidget: Column( timerWidget: (_timeRemaining == null || _timeRemaining == Duration.zero)
? null
: Column(
children: [ children: [
SizedBox( SizedBox(height: 16.w),
height: 16.w, Divider(height: 1, color: AppColors.dividerColor),
), SizedBox(height: 16.w),
Divider(
height: 1,
color: AppColors.dividerColor,
),
SizedBox(
height: 16.w,
),
Directionality( Directionality(
textDirection: ui.TextDirection.ltr, textDirection: ui.TextDirection.ltr,
child: Row( child: Row(
@ -384,28 +384,28 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
children: [ children: [
Expanded( Expanded(
child: _buildTimeUnit( child: _buildTimeUnit(
_timeRemaining != null ? _timeRemaining!.inDays.toString().padLeft(2, '0') : '00', _timeRemaining!.inDays.toString().padLeft(2, '0'),
LocaleKeys.days.tr(context: context), LocaleKeys.days.tr(context: context),
), ),
), ),
_buildTimeSeparator(), _buildTimeSeparator(),
Expanded( Expanded(
child: _buildTimeUnit( child: _buildTimeUnit(
_timeRemaining != null ? _timeRemaining!.inHours.remainder(24).toString().padLeft(2, '0') : '00', _timeRemaining!.inHours.remainder(24).toString().padLeft(2, '0'),
LocaleKeys.hours.tr(context: context), LocaleKeys.hours.tr(context: context),
), ),
), ),
_buildTimeSeparator(), _buildTimeSeparator(),
Expanded( Expanded(
child: _buildTimeUnit( child: _buildTimeUnit(
_timeRemaining != null ? _timeRemaining!.inMinutes.remainder(60).toString().padLeft(2, '0') : '00', _timeRemaining!.inMinutes.remainder(60).toString().padLeft(2, '0'),
LocaleKeys.minutes.tr(context: context), LocaleKeys.minutes.tr(context: context),
), ),
), ),
_buildTimeSeparator(), _buildTimeSeparator(),
Expanded( Expanded(
child: _buildTimeUnit( child: _buildTimeUnit(
_timeRemaining != null ? _timeRemaining!.inSeconds.remainder(60).toString().padLeft(2, '0') : '00', _timeRemaining!.inSeconds.remainder(60).toString().padLeft(2, '0'),
LocaleKeys.seconds.tr(context: context), LocaleKeys.seconds.tr(context: context),
), ),
), ),
@ -603,6 +603,7 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
), ),
const Spacer(), const Spacer(),
BellAnimatedSwitch( BellAnimatedSwitch(
key: _bellSwitchKey,
initialValue: widget.patientAppointmentHistoryResponseModel.hasReminder ?? false, initialValue: widget.patientAppointmentHistoryResponseModel.hasReminder ?? false,
activeColor: AppColors.successColor.withOpacity(0.2), activeColor: AppColors.successColor.withOpacity(0.2),
inactiveColor: AppColors.lightGrayBGColor, inactiveColor: AppColors.lightGrayBGColor,
@ -618,7 +619,9 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
if (newValue == true) { if (newValue == true) {
DateTime startDate = DateTime.now(); DateTime startDate = DateTime.now();
DateTime endDate = DateUtil.convertStringToDate(widget.patientAppointmentHistoryResponseModel.appointmentDate); DateTime endDate = DateUtil.convertStringToDate(widget.patientAppointmentHistoryResponseModel.appointmentDate);
BottomSheetUtils().showReminderBottomSheet(
// Show reminder bottom sheet and check if permission was granted
bool permissionGranted = await BottomSheetUtils().showReminderBottomSheet(
context, context,
endDate, endDate,
widget.patientAppointmentHistoryResponseModel.doctorNameObj ?? "", widget.patientAppointmentHistoryResponseModel.doctorNameObj ?? "",
@ -649,6 +652,11 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
}); });
}, },
); );
// If permission was not granted, revert the switch back to OFF
if (!permissionGranted) {
_bellSwitchKey.currentState?.setSwitchValue(false);
}
} else { } else {
isEventAddedOrRemoved = await calender.checkAndRemove( isEventAddedOrRemoved = await calender.checkAndRemove(
id: "${widget.patientAppointmentHistoryResponseModel.appointmentNo}", id: "${widget.patientAppointmentHistoryResponseModel.appointmentNo}",
@ -1210,8 +1218,7 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
handleAppointmentNextAction(widget.patientAppointmentHistoryResponseModel.nextAction); handleAppointmentNextAction(widget.patientAppointmentHistoryResponseModel.nextAction);
}, },
backgroundColor: AppointmentType.getNextActionButtonColor(widget.patientAppointmentHistoryResponseModel.nextAction), backgroundColor: AppointmentType.getNextActionButtonColor(widget.patientAppointmentHistoryResponseModel.nextAction),
borderColor: borderColor: AppointmentType.getNextActionButtonColor(widget.patientAppointmentHistoryResponseModel.nextAction).withValues(alpha: 0.01),
AppointmentType.getNextActionButtonColor(widget.patientAppointmentHistoryResponseModel.nextAction).withValues(alpha: 0.01),
textColor: widget.patientAppointmentHistoryResponseModel.nextAction == 15 ? AppColors.textColor : Colors.white, textColor: widget.patientAppointmentHistoryResponseModel.nextAction == 15 ? AppColors.textColor : Colors.white,
fontSize: 16.f, fontSize: 16.f,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@ -1392,9 +1399,10 @@ class _AppointmentDetailsPageState extends State<AppointmentDetailsPage> {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Lottie.asset(AppAnimations.warningAnimation, Lottie.asset(AppAnimations.warningAnimation, repeat: false, reverse: false, frameRate: FrameRate(60), width: 100.h, height: 100.h, fit: BoxFit.fill),
repeat: false, reverse: false, frameRate: FrameRate(60), width: 100.h, height: 100.h, fit: BoxFit.fill), SizedBox(
SizedBox(height: 12,), height: 12,
),
LocaleKeys.upcomingPaymentPending.tr(context: context).toText14(color: AppColors.textColor, isCenter: true), LocaleKeys.upcomingPaymentPending.tr(context: context).toText14(color: AppColors.textColor, isCenter: true),
SizedBox(height: 24.h), SizedBox(height: 24.h),
// // Countdown Timer - DD : HH : MM : SS format with labels - Always LTR // // Countdown Timer - DD : HH : MM : SS format with labels - Always LTR

@ -33,10 +33,10 @@ class BellAnimatedSwitch extends StatefulWidget {
}); });
@override @override
State<BellAnimatedSwitch> createState() => _BellAnimatedSwitchState(); State<BellAnimatedSwitch> createState() => BellAnimatedSwitchState();
} }
class _BellAnimatedSwitchState extends State<BellAnimatedSwitch> with SingleTickerProviderStateMixin { class BellAnimatedSwitchState extends State<BellAnimatedSwitch> with SingleTickerProviderStateMixin {
late bool _isActive; late bool _isActive;
late AnimationController _animationController; late AnimationController _animationController;
late Animation<Alignment> _circleAlignment; late Animation<Alignment> _circleAlignment;
@ -51,11 +51,7 @@ class _BellAnimatedSwitchState extends State<BellAnimatedSwitch> with SingleTick
vsync: this, vsync: this,
); );
// Animation for the circle position (left/right) _circleAlignment = AlignmentTween(begin: Alignment.centerLeft, end: Alignment.centerRight).animate(
_circleAlignment = AlignmentTween(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
).animate(
CurvedAnimation(parent: _animationController, curve: Curves.easeInOut), CurvedAnimation(parent: _animationController, curve: Curves.easeInOut),
); );
@ -78,6 +74,24 @@ class _BellAnimatedSwitchState extends State<BellAnimatedSwitch> with SingleTick
super.dispose(); super.dispose();
} }
/// Public method to set switch value programmatically without triggering onChanged callback
void setSwitchValue(bool value, {bool animate = true}) {
if (_isActive == value) return; // No change needed
setState(() {
_isActive = value;
if (animate) {
if (_isActive) {
_animationController.forward();
} else {
_animationController.reverse();
}
} else {
_animationController.value = _isActive ? 1.0 : 0.0;
}
});
}
void _toggle() { void _toggle() {
setState(() { setState(() {
_isActive = !_isActive; _isActive = !_isActive;
@ -106,13 +120,15 @@ class _BellAnimatedSwitchState extends State<BellAnimatedSwitch> with SingleTick
Widget _getIcon() { Widget _getIcon() {
if (_isActive) { if (_isActive) {
return widget.activeIcon ?? Icon( return widget.activeIcon ??
Icon(
Icons.check, Icons.check,
size: 18, size: 18,
color: widget.activeIconColor ?? Colors.green.shade400, color: widget.activeIconColor ?? Colors.green.shade400,
); );
} }
return widget.inactiveIcon ?? Icon( return widget.inactiveIcon ??
Icon(
Icons.close, Icons.close,
size: 18, size: 18,
color: widget.inactiveIconColor ?? Colors.grey.shade600, color: widget.inactiveIconColor ?? Colors.grey.shade600,
@ -162,9 +178,7 @@ class _BellAnimatedSwitchState extends State<BellAnimatedSwitch> with SingleTick
), ),
], ],
), ),
child: Center( child: Center(child: _getIcon()),
child: _getIcon(),
),
), ),
), ),
], ],

@ -1,5 +1,6 @@
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 'dart:ui' as ui;
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/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';
@ -138,7 +139,9 @@ class PatientInformationStepState extends State<PatientInformationStep> {
} }
Widget _buildPatientPhoneField(ReferralFormManager formManager) { Widget _buildPatientPhoneField(ReferralFormManager formManager) {
return Focus( return Directionality(
textDirection: ui.TextDirection.ltr,
child: Focus(
focusNode: _phoneFocusNode, focusNode: _phoneFocusNode,
child: TextInputWidget( child: TextInputWidget(
labelText: LocaleKeys.phoneNumber.tr(context: context), labelText: LocaleKeys.phoneNumber.tr(context: context),
@ -162,6 +165,7 @@ class PatientInformationStepState extends State<PatientInformationStep> {
errorMessage: formManager.errors.patientPhone, errorMessage: formManager.errors.patientPhone,
hasError: !ValidationUtils.isNullOrEmpty(formManager.errors.patientPhone) hasError: !ValidationUtils.isNullOrEmpty(formManager.errors.patientPhone)
).paddingSymmetrical(0, 8), ).paddingSymmetrical(0, 8),
),
); );
} }

@ -17,64 +17,75 @@ import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
class BottomSheetUtils { class BottomSheetUtils {
showReminderBottomSheet(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted, Future<bool> showReminderBottomSheet(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted,
{required Function() onSuccess, String? title, String? description, Function(int)? onMultiDateSuccess, bool isMultiAllowed = false}) async { {required Function() onSuccess, String? title, String? description, Function(int)? onMultiDateSuccess, bool isMultiAllowed = false}) async {
// Check and request permissions based on platform
bool hasPermission = await _checkAndRequestCalendarPermissions();
if (hasPermission) {
// Permission granted, show the reminder selection bottom sheet
await _showReminderBottomSheet(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted,
onSuccess: onSuccess, title: title, description: description, onMultiDateSuccess: onMultiDateSuccess, isMultiAllowed: isMultiAllowed);
return true;
} else {
await _showPermissionDeniedDialog();
return false;
}
}
/// Checks and requests calendar permissions for both Android and iOS
/// Returns true if all required permissions are granted
Future<bool> _checkAndRequestCalendarPermissions() async {
if (Platform.isAndroid) { if (Platform.isAndroid) {
// Android: Check existing permission first using PermissionService
bool hasPermission = await PermissionService.isCalendarPermissionEnabled(); bool hasPermission = await PermissionService.isCalendarPermissionEnabled();
if (!hasPermission) { if (hasPermission) {
return true;
}
// Request calendarFullAccess permission (Android 14+ requires this)
// This internally requests both READ_CALENDAR and WRITE_CALENDAR
PermissionStatus status = await Permission.calendarFullAccess.request(); PermissionStatus status = await Permission.calendarFullAccess.request();
hasPermission = status.isGranted;
// If calendarFullAccess request didn't show dialog or failed,
// fallback to requesting individual permissions
if (!status.isGranted) {
Map<Permission, PermissionStatus> statuses = await [
Permission.calendarWriteOnly,
].request();
return statuses[Permission.calendarWriteOnly]?.isGranted ?? false;
} }
if (hasPermission) {
_showReminderBottomSheet(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted, return status.isGranted;
onSuccess: onSuccess, title: title, description: description, onMultiDateSuccess: onMultiDateSuccess, isMultiAllowed: isMultiAllowed);
} else { } else {
showCommonBottomSheetWithoutHeight( // iOS: Check if we already have full access
title: LocaleKeys.notice.tr(context: GetIt.instance<NavigationService>().navigatorKey.currentContext!), PermissionStatus fullAccessStatus = await Permission.calendarFullAccess.status;
GetIt.instance<NavigationService>().navigatorKey.currentContext!,
child: Utils.getWarningWidget( if (fullAccessStatus.isGranted) {
loadingText: LocaleKeys.calendarPermissionAlert.tr(), return true;
isShowActionButtons: true,
onCancelTap: () {
GetIt.instance<NavigationService>().pop();
},
onConfirmTap: () async {
GetIt.instance<NavigationService>().pop();
openAppSettings();
}),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
} }
} else {
if (await Permission.calendarWriteOnly.request().isGranted) { // Request write permission first (required before full access on iOS)
if (await Permission.calendarFullAccess.request().isGranted) { PermissionStatus writeStatus = await Permission.calendarWriteOnly.request();
_showReminderBottomSheet(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted, if (!writeStatus.isGranted) {
onSuccess: onSuccess, title: title, description: description, onMultiDateSuccess: onMultiDateSuccess, isMultiAllowed: isMultiAllowed); return false;
} else {
showCommonBottomSheetWithoutHeight(
title: LocaleKeys.notice.tr(context: GetIt.instance<NavigationService>().navigatorKey.currentContext!),
GetIt.instance<NavigationService>().navigatorKey.currentContext!,
child: Utils.getWarningWidget(
loadingText: LocaleKeys.calendarPermissionAlert.tr(),
isShowActionButtons: true,
onCancelTap: () {
GetIt.instance<NavigationService>().pop();
},
onConfirmTap: () async {
GetIt.instance<NavigationService>().pop();
openAppSettings();
}),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
} }
} else {
// Then request full access permission
PermissionStatus fullStatus = await Permission.calendarFullAccess.request();
return fullStatus.isGranted;
}
}
/// Shows permission denied dialog with option to open settings
Future<void> _showPermissionDeniedDialog() async {
BuildContext? context = GetIt.instance<NavigationService>().navigatorKey.currentContext;
if (context == null) return;
showCommonBottomSheetWithoutHeight( showCommonBottomSheetWithoutHeight(
title: LocaleKeys.notice.tr(context: GetIt.instance<NavigationService>().navigatorKey.currentContext!), context,
GetIt.instance<NavigationService>().navigatorKey.currentContext!, title: LocaleKeys.notice.tr(context: context),
child: Utils.getWarningWidget( child: Utils.getWarningWidget(
loadingText: LocaleKeys.calendarPermissionAlert.tr(), loadingText: LocaleKeys.calendarPermissionAlert.tr(),
isShowActionButtons: true, isShowActionButtons: true,
@ -83,15 +94,14 @@ class BottomSheetUtils {
}, },
onConfirmTap: () async { onConfirmTap: () async {
GetIt.instance<NavigationService>().pop(); GetIt.instance<NavigationService>().pop();
openAppSettings(); await openAppSettings();
}), },
),
callBackFunc: () {}, callBackFunc: () {},
isFullScreen: false, isFullScreen: false,
isCloseButtonVisible: true, isCloseButtonVisible: true,
); );
} }
}
}
Future<void> _showReminderBottomSheet(BuildContext providedContext, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted, Future<void> _showReminderBottomSheet(BuildContext providedContext, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted,
{required Function onSuccess, String? title, String? description, Function(int)? onMultiDateSuccess, bool? isMultiAllowed}) async { {required Function onSuccess, String? title, String? description, Function(int)? onMultiDateSuccess, bool? isMultiAllowed}) async {

Loading…
Cancel
Save