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.
126 lines
4.5 KiB
Dart
126 lines
4.5 KiB
Dart
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/custom_radio.dart';
|
|
import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manage_calendar_events/manage_calendar_events.dart';
|
|
|
|
class PrescriptionReminderDialog extends StatefulWidget {
|
|
static var selectedDuration;
|
|
|
|
final String eventId;
|
|
final String title;
|
|
final String description;
|
|
final DateTime startDate;
|
|
final DateTime endDate;
|
|
final String location;
|
|
final int days;
|
|
|
|
List<DateTime> _scheduleList = List();
|
|
|
|
PrescriptionReminderDialog({
|
|
@required this.eventId,
|
|
@required this.title,
|
|
@required this.description,
|
|
@required this.startDate,
|
|
@required this.endDate,
|
|
@required this.location,
|
|
@required this.days,
|
|
});
|
|
|
|
@override
|
|
_ReminderDialogState createState() => _ReminderDialogState();
|
|
}
|
|
|
|
class _ReminderDialogState extends State<PrescriptionReminderDialog> {
|
|
final CalendarPlugin _myPlugin = CalendarPlugin();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
child: Dialog(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
|
|
child: Container(
|
|
// height: MediaQuery.of(context).size.height * 0.57,
|
|
width: 450.0,
|
|
child:
|
|
Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: <Widget>[
|
|
Container(
|
|
margin: EdgeInsets.all(20.0),
|
|
child: Text(TranslationBase.of(context).setReminder,
|
|
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold)),
|
|
),
|
|
Container(
|
|
transform: Matrix4.translationValues(0.0, -30.0, 0.0),
|
|
child: CustomRadio(),
|
|
),
|
|
Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: 40.0,
|
|
margin: EdgeInsets.only(left: 30.0, top: 0.0, right: 30.0),
|
|
child: RaisedButton(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10.0), side: BorderSide(color: Colors.blue)),
|
|
color: Colors.blue,
|
|
onPressed: () {
|
|
createOrUpdateEvents();
|
|
},
|
|
child: Text(TranslationBase.of(context).confirm,
|
|
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
),
|
|
),
|
|
Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
margin: EdgeInsets.only(left: 100.0, top: 20.0, right: 100.0, bottom: 20.0),
|
|
child: OutlineButton(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
|
|
color: Colors.red,
|
|
borderSide: BorderSide(color: Colors.red),
|
|
highlightColor: Colors.red,
|
|
highlightedBorderColor: Colors.red,
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text(TranslationBase.of(context).cancel_nocaps,
|
|
style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
createOrUpdateEvents() async {
|
|
Navigator.pop(context);
|
|
|
|
for (int count = 0; count < widget.days; count++) {
|
|
widget._scheduleList.add(DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day));
|
|
}
|
|
|
|
List<DateTime> scheduleDateTime = calculateDaysInterval(
|
|
widget.startDate.subtract(new Duration(microseconds: PrescriptionReminderDialog.selectedDuration)),
|
|
widget.endDate);
|
|
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
|
|
calendarUtils.createOrUpdateEvents(
|
|
scheduleList: widget._scheduleList,
|
|
description: widget.description,
|
|
title: widget.title,
|
|
scheduleDateTime: scheduleDateTime);
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
|
|
}
|
|
|
|
List<DateTime> calculateDaysInterval(DateTime startDate, DateTime endDate) {
|
|
List<DateTime> days = [];
|
|
for (int i = 0; i <= endDate.difference(startDate).inDays; i++) {
|
|
widget._scheduleList.forEach((element) {
|
|
days.add(startDate.add(Duration(days: i, hours: element.hour, minutes: element.minute)));
|
|
});
|
|
}
|
|
return days;
|
|
}
|
|
}
|