You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PatientApp-KKUMC/lib/pages/BookAppointment/widgets/reminder_dialog.dart

260 lines
9.1 KiB
Dart

import 'dart:io';
import 'package:diplomaticquarterapp/analytics/google-analytics.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/services/permission/permission_service.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:flutter/material.dart';
4 years ago
import 'package:jiffy/jiffy.dart';
import 'package:manage_calendar_events/manage_calendar_events.dart';
import 'package:permission_handler/permission_handler.dart';
Future<Map<Permission, PermissionStatus>> requestPermissions() async {
var permissionResults = [Permission.calendarFullAccess].request();
4 years ago
return permissionResults;
}
showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted,
{required Function onSuccess, String? title, String? description, Function(int)? onMultiDateSuccess}) async {
if (Platform.isAndroid) {
3 years ago
if (await PermissionService.isCalendarPermissionEnabled()) {
_showReminderDialog(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted,
onSuccess: onSuccess, title: title ?? "", description: description ?? "", onMultiDateSuccess: onMultiDateSuccess ?? (int) {});
} else {
Utils.showPermissionConsentDialog(context, TranslationBase.of(context).calendarPermission, () async {
if (await Permission.calendarFullAccess.request().isGranted) {
_showReminderDialog(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted,
onSuccess: onSuccess, title: title ?? "", description: description ?? "", onMultiDateSuccess: onMultiDateSuccess ?? (int) {});
}
});
}
4 years ago
} else {
if (await Permission.calendarFullAccess.request().isGranted) {
_showReminderDialog(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted,
onSuccess: onSuccess, title: title ?? "", description: description ?? "", onMultiDateSuccess: onMultiDateSuccess ?? (int) {});
}
4 years ago
}
}
final CalendarPlugin _myPlugin = CalendarPlugin();
Future<void> _showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted,
{required Function onSuccess, required String title, required String description, required Function(int) onMultiDateSuccess}) async {
4 years ago
return showDialog<void>(
context: context,
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0.0)),
insetPadding: EdgeInsets.all(21),
4 years ago
child: ReminderDialog(
onClick: (int i) async {
String text = "";
4 years ago
if (i == 0) {
// Before 30 mints
dateTime = Jiffy.parseFromDateTime(dateTime).subtract(minutes: 30).dateTime;
text = "30 minutes";
4 years ago
// dateTime.add(new Duration(minutes: -30));
} else if (i == 1) {
// Before 1 hour
// dateTime.add(new Duration(minutes: -60));
dateTime = Jiffy.parseFromDateTime(dateTime).subtract(hours: 1).dateTime;
text = "1 hours";
4 years ago
} else if (i == 2) {
// Before 1 hour and 30 mints
// dateTime.add(new Duration(minutes: -90));
dateTime = Jiffy.parseFromDateTime(dateTime).subtract(hours: 1, minutes: 30).dateTime;
text = "1 hours 30 minutes";
4 years ago
} else if (i == 3) {
// Before 2 hours
// dateTime.add(new Duration(minutes: -120));
dateTime = Jiffy.parseFromDateTime(dateTime).subtract(hours: 2).dateTime;
text = "2 hours";
4 years ago
}
if (onMultiDateSuccess == null) {
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
calendarUtils
.createOrUpdateEvent(
title: title ?? TranslationBase.of(context).reminderTitle + " " + doctorName,
description: description ?? "At " + appoDateFormatted + " " + appoTimeFormatted,
scheduleDateTime: dateTime,
eventId: eventId)
.then((value) {});
4 years ago
onSuccess();
} else {
onMultiDateSuccess(i);
}
locator<GAnalytics>().appointment.appointment_reminder_time(reminde_before: text);
4 years ago
},
),
);
},
);
}
class ReminderDialog extends StatefulWidget {
Function? onClick;
ReminderDialog({this.onClick});
@override
_ReminderDialogState createState() => _ReminderDialogState();
}
class _ReminderDialogState extends State<ReminderDialog> {
int i = 0;
@override
Widget build(BuildContext context) {
return Container(
//width: MediaQuery.of(context).size.width / 0.8,
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Icons.notifications_active,
color: Color(0xff2B353E),
size: 50,
),
IconButton(
icon: Icon(Icons.clear),
color: Color(0xff2B353E),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
mHeight(20),
Text(
4 years ago
TranslationBase.of(context).appointmentReminder,
style: TextStyle(
fontSize: 16,
color: Color(0xff2B353E),
fontWeight: FontWeight.w600,
letterSpacing: -0.48,
),
),
mHeight(20),
Text(
4 years ago
TranslationBase.of(context).pleaseSelectFromBelowOptions,
style: TextStyle(
fontSize: 12,
color: Color(0xff2B353E),
fontWeight: FontWeight.w600,
letterSpacing: -0.48,
),
),
4 years ago
Row(
children: [
Radio<int>(
value: 0,
groupValue: i,
onChanged: (int? value) {
4 years ago
setState(() {
i = value!;
4 years ago
});
},
),
Text(
TranslationBase.of(context).appoReminder30,
4 years ago
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
letterSpacing: -0.48,
),
),
4 years ago
],
),
4 years ago
Row(
children: [
Radio<int>(
value: 1,
groupValue: i,
onChanged: (int? value) {
4 years ago
setState(() {
i = value!;
4 years ago
});
},
),
Text(
TranslationBase.of(context).appoReminder60,
4 years ago
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
letterSpacing: -0.48,
),
),
4 years ago
],
),
4 years ago
Row(
children: [
Radio<int>(
value: 2,
groupValue: i,
onChanged: (int? value) {
4 years ago
setState(() {
i = value!;
4 years ago
});
},
),
Text(
TranslationBase.of(context).appoReminder90,
4 years ago
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
letterSpacing: -0.48,
),
),
4 years ago
],
),
4 years ago
Row(
children: [
Radio<int>(
value: 3,
groupValue: i,
onChanged: (int? value) {
4 years ago
setState(() {
i = value!;
4 years ago
});
},
),
Text(
TranslationBase.of(context).appoReminder120,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
letterSpacing: -0.48,
),
),
],
),
mHeight(12),
DefaultButton(
TranslationBase.of(context).save,
() {
widget.onClick!(i);
Navigator.pop(context);
},
color: CustomColors.green,
),
],
),
);
}
}