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.
221 lines
6.8 KiB
Dart
221 lines
6.8 KiB
Dart
import 'package:diplomaticquarterapp/theme/colors.dart';
|
|
import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
|
|
import 'package:flutter/material.dart';
|
|
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.calendar].request();
|
|
return permissionResults;
|
|
}
|
|
|
|
showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted, {Function onSuccess}) async {
|
|
if (await Permission.calendar.request().isGranted) {
|
|
_showReminderDialog(
|
|
context,
|
|
dateTime,
|
|
doctorName,
|
|
eventId,
|
|
appoDateFormatted,
|
|
appoTimeFormatted,
|
|
onSuccess: onSuccess,
|
|
);
|
|
} else {
|
|
requestPermissions().then((results) {
|
|
if (results[Permission.calendar].isGranted) {
|
|
_showReminderDialog(
|
|
context,
|
|
dateTime,
|
|
doctorName,
|
|
eventId,
|
|
appoDateFormatted,
|
|
appoTimeFormatted,
|
|
onSuccess: onSuccess,
|
|
);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
final CalendarPlugin _myPlugin = CalendarPlugin();
|
|
|
|
Future<void> _showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted, {Function onSuccess}) async {
|
|
return showDialog<void>(
|
|
context: context,
|
|
barrierDismissible: true, // user must tap button!
|
|
builder: (BuildContext context) {
|
|
return Dialog(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)), //this right here
|
|
child: ReminderDialog(
|
|
onClick: (int i) async {
|
|
if (i == 0) {
|
|
// Before 30 mints
|
|
dateTime = Jiffy(dateTime).subtract(minutes: 30);
|
|
// dateTime.add(new Duration(minutes: -30));
|
|
} else if (i == 1) {
|
|
// Before 1 hour
|
|
// dateTime.add(new Duration(minutes: -60));
|
|
dateTime = Jiffy(dateTime).subtract(hours: 1);
|
|
} else if (i == 2) {
|
|
// Before 1 hour and 30 mints
|
|
// dateTime.add(new Duration(minutes: -90));
|
|
dateTime = Jiffy(dateTime).subtract(hours: 1, minutes: 30);
|
|
} else if (i == 3) {
|
|
// Before 2 hours
|
|
// dateTime.add(new Duration(minutes: -120));
|
|
dateTime = Jiffy(dateTime).subtract(hours: 2);
|
|
}
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
calendarUtils
|
|
.createOrUpdateEvent(
|
|
title: TranslationBase.of(context).reminderTitle + " " + doctorName, description: "At " + appoDateFormatted + " " + appoTimeFormatted, scheduleDateTime: dateTime, eventId: eventId)
|
|
.then((value) {});
|
|
|
|
onSuccess();
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
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,
|
|
children: [
|
|
Icon(
|
|
Icons.notifications_active,
|
|
size: 50,
|
|
),
|
|
IconButton(
|
|
icon: Icon(Icons.clear),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
mHeight(20),
|
|
Text(
|
|
"When would you like to set a reminder for this appointment?",
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.48,
|
|
),
|
|
),
|
|
mHeight(20),
|
|
Text(
|
|
"Please select from below options:",
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.48,
|
|
),
|
|
),
|
|
ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: const Text('Before 30 Mins'),
|
|
leading: Radio<int>(
|
|
value: 0,
|
|
groupValue: i,
|
|
onChanged: (int value) {
|
|
setState(() {
|
|
i = value;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: const Text('Before 1 Hour'),
|
|
leading: Radio<int>(
|
|
value: 1,
|
|
groupValue: i,
|
|
onChanged: (int value) {
|
|
setState(() {
|
|
i = value;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: const Text('Before 1 Hour and 30 Mins'),
|
|
leading: Radio<int>(
|
|
value: 2,
|
|
groupValue: i,
|
|
onChanged: (int value) {
|
|
setState(() {
|
|
i = value;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: const Text('Before 2 Hours'),
|
|
leading: Radio<int>(
|
|
value: 3,
|
|
groupValue: i,
|
|
onChanged: (int value) {
|
|
setState(() {
|
|
i = value;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
mHeight(12),
|
|
InkWell(
|
|
onTap: () {
|
|
widget.onClick(i);
|
|
Navigator.pop(context);
|
|
},
|
|
child: Container(
|
|
width: double.infinity,
|
|
height: 45,
|
|
decoration: containerRadius(CustomColors.green, 12),
|
|
child: Center(
|
|
child: Text(
|
|
"Save",
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
letterSpacing: -0.48,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|