Merge remote-tracking branch 'origin/master' into watch_integration
# Conflicts: # android/app/build.gradle.kts # android/app/src/main/res/mipmap-hdpi/ic_launcher.png # android/app/src/main/res/mipmap-mdpi/ic_launcher.png # android/app/src/main/res/mipmap-xhdpi/ic_launcher.png # android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png # android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png # android/app/src/main2/res/mipmap-hdpi/ic_launcher.png # android/app/src/main2/res/mipmap-mdpi/ic_launcher.png # android/app/src/main2/res/mipmap-xhdpi/ic_launcher.png # android/app/src/main2/res/mipmap-xxhdpi/ic_launcher.png # android/app/src/main2/res/mipmap-xxxhdpi/ic_launcher.png # android/build/reports/problems/problems-report.html # assets/langs/ar-SA.json # assets/langs/en-US.json # lib/generated/locale_keys.g.dart # lib/theme/colors.dart # package/device_calendar_plus/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png # package/device_calendar_plus/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png # package/device_calendar_plus/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png # package/device_calendar_plus/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png # package/device_calendar_plus/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png # pubspec.yamlwatch_integration
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 949 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
@ -0,0 +1 @@
|
||||
{"images":[{"size":"60x60","expected-size":"180","filename":"180.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"40x40","expected-size":"80","filename":"80.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"40x40","expected-size":"120","filename":"120.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"60x60","expected-size":"120","filename":"120.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"57x57","expected-size":"57","filename":"57.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"1x"},{"size":"29x29","expected-size":"58","filename":"58.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"29x29","expected-size":"29","filename":"29.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"1x"},{"size":"29x29","expected-size":"87","filename":"87.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"57x57","expected-size":"114","filename":"114.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"20x20","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"20x20","expected-size":"60","filename":"60.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"1024x1024","filename":"1024.png","expected-size":"1024","idiom":"ios-marketing","folder":"Assets.xcassets/AppIcon.appiconset/","scale":"1x"},{"size":"40x40","expected-size":"80","filename":"80.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"72x72","expected-size":"72","filename":"72.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"76x76","expected-size":"152","filename":"152.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"50x50","expected-size":"100","filename":"100.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"29x29","expected-size":"58","filename":"58.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"76x76","expected-size":"76","filename":"76.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"29x29","expected-size":"29","filename":"29.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"50x50","expected-size":"50","filename":"50.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"72x72","expected-size":"144","filename":"144.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"40x40","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"83.5x83.5","expected-size":"167","filename":"167.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"20x20","expected-size":"20","filename":"20.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"20x20","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"}]}
|
||||
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 40 KiB |
@ -0,0 +1,3 @@
|
||||
<svg width="21" height="21" viewBox="0 0 21 21" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8.76629 0.292994C8.94577 0.52652 8.97196 0.843482 8.83323 1.10329C8.24927 2.19693 7.91792 3.4461 7.91792 4.77489C7.91792 9.0867 11.4133 12.5821 15.7251 12.5821C17.0539 12.5821 18.3031 12.2508 19.3967 11.6668C19.6565 11.5281 19.9735 11.5543 20.207 11.7337C20.4406 11.9132 20.5474 12.2128 20.4802 12.4995C19.4056 17.085 15.2909 20.5 10.3769 20.5C4.64589 20.5 0 15.8541 0 10.1232C0 5.20909 3.41505 1.09448 8.0005 0.0198166C8.28726 -0.0473898 8.58681 0.0594678 8.76629 0.292994Z" fill="#8F9AA3"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 610 B |
@ -1,4 +1,3 @@
|
||||
<svg height="1792" id="download" width="1792" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M1344 1344q0-26-19-45t-45-19-45 19-19 45 19 45 45 19 45-19 19-45zm256 0q0-26-19-45t-45-19-45 19-19 45 19 45 45 19 45-19 19-45zm128-224v320q0 40-28 68t-68 28H160q-40 0-68-28t-28-68v-320q0-40 28-68t68-28h465l135 136q58 56 136 56t136-56l136-136h464q40 0 68 28t28 68zm-325-569q17 41-14 70l-448 448q-18 19-45 19t-45-19L403 621q-31-29-14-70 17-39 59-39h256V64q0-26 19-45t45-19h256q26 0 45 19t19 45v448h256q42 0 59 39z"></path>
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.73038 1.67378e-07L7.73039 1.67378e-07C9.37341 -9.67694e-06 10.6639 -1.7412e-05 11.6715 0.135446C12.704 0.274261 13.5232 0.564537 14.1668 1.20819C14.8105 1.85183 15.1007 2.67102 15.2396 3.70352C15.375 4.71108 15.375 6.0016 15.375 7.64462V7.7304C15.375 9.37342 15.375 10.6639 15.2396 11.6715C15.1007 12.704 14.8105 13.5232 14.1668 14.1668C13.5232 14.8105 12.704 15.1007 11.6715 15.2396C10.6639 15.375 9.3734 15.375 7.73038 15.375H7.6446C6.00158 15.375 4.71108 15.375 3.70352 15.2396C2.67102 15.1007 1.85183 14.8105 1.20819 14.1668C0.564537 13.5232 0.274261 12.704 0.135446 11.6715C-1.7412e-05 10.6639 -9.67693e-06 9.37341 1.67378e-07 7.73039L1.67378e-07 7.73038L1.67378e-07 7.64462L1.67378e-07 7.64461C-9.67693e-06 6.00159 -1.7412e-05 4.71108 0.135446 3.70352C0.274261 2.67102 0.564537 1.85183 1.20819 1.20819C1.85183 0.564537 2.67102 0.274261 3.70352 0.135446C4.71108 -1.7412e-05 6.00159 -9.67694e-06 7.64461 1.67378e-07L7.64462 1.67378e-07L7.73038 1.67378e-07ZM7.6875 3.1875C8.10171 3.1875 8.4375 3.52329 8.4375 3.9375V6.28379H8.85004L8.86442 6.28376C8.9186 6.28359 9.02672 6.28324 9.12235 6.29699C9.20821 6.30934 9.59436 6.37258 9.77265 6.77369C9.95094 7.1748 9.73916 7.50383 9.6908 7.57583C9.63693 7.65604 9.56422 7.73607 9.5278 7.77617L9.51814 7.78682L9.01431 8.34503C8.84929 8.52797 8.67863 8.71716 8.51617 8.85448C8.33191 9.01023 8.05864 9.1875 7.6875 9.1875C7.31636 9.1875 7.04308 9.01023 6.85883 8.85448C6.69637 8.71716 6.52571 8.52796 6.36069 8.34502L5.85686 7.78682L5.8472 7.77616C5.81077 7.73607 5.73807 7.65603 5.6842 7.57583C5.63584 7.50383 5.42406 7.1748 5.60235 6.77369C5.78064 6.37258 6.16679 6.30934 6.25265 6.29699C6.34828 6.28324 6.4564 6.28359 6.51058 6.28376L6.52496 6.28379H6.9375L6.9375 3.9375C6.9375 3.52329 7.27329 3.1875 7.6875 3.1875ZM4.6875 11.4375C4.6875 11.0233 5.02329 10.6875 5.4375 10.6875H9.9375C10.3517 10.6875 10.6875 11.0233 10.6875 11.4375C10.6875 11.8517 10.3517 12.1875 9.9375 12.1875H5.4375C5.02329 12.1875 4.6875 11.8517 4.6875 11.4375Z" fill="#F43333"/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 531 B After Width: | Height: | Size: 2.1 KiB |
@ -1,316 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:device_calendar/device_calendar.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:hmg_patient_app_new/core/dependencies.dart';
|
||||
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
|
||||
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
||||
import 'package:hmg_patient_app_new/presentation/prescriptions/prescription_reminder_view.dart';
|
||||
import 'package:hmg_patient_app_new/services/dialog_service.dart';
|
||||
import 'package:hmg_patient_app_new/services/permission_service.dart';
|
||||
import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:manage_calendar_events/manage_calendar_events.dart' as ios;
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:timezone/data/latest.dart' as tzl;
|
||||
|
||||
final DeviceCalendarPlugin deviceCalendarPlugin = DeviceCalendarPlugin();
|
||||
final ios.CalendarPlugin _myPlugin = ios.CalendarPlugin();
|
||||
|
||||
class CalendarUtils {
|
||||
static Completer<CalendarUtils>? _completer;
|
||||
|
||||
dynamic get writableCalendars => calendars.firstWhere((c) => !c.isReadOnly!);
|
||||
dynamic calendars;
|
||||
|
||||
CalendarUtils._(this.calendars);
|
||||
|
||||
// static Future<CalendarUtils> getInstance() async {
|
||||
// if (_completer == null) {
|
||||
// _completer = Completer<CalendarUtils>();
|
||||
// print(_completer!.isCompleted);
|
||||
// try {
|
||||
// final dynamic calendarsResult;
|
||||
// if (Platform.isIOS) {
|
||||
// calendarsResult = await _myPlugin.getCalendars();
|
||||
// if (!_completer!.isCompleted) {
|
||||
// _completer?.complete(CalendarUtils._(await calendarsResult!));
|
||||
// }
|
||||
// } else {
|
||||
// calendarsResult = await deviceCalendarPlugin.retrieveCalendars();
|
||||
// if (!_completer!.isCompleted) {
|
||||
// _completer?.complete(CalendarUtils._(await calendarsResult.data!));
|
||||
// }
|
||||
// }
|
||||
// } on Exception catch (e) {
|
||||
// if (!_completer!.isCompleted) {
|
||||
// _completer!.completeError(e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return _completer!.future;
|
||||
// }
|
||||
|
||||
static Future<CalendarUtils> getInstance() async {
|
||||
tzl.initializeTimeZones();
|
||||
if (_completer != null) {
|
||||
return _completer!.future;
|
||||
}
|
||||
_completer = Completer<CalendarUtils>();
|
||||
try {
|
||||
final dynamic calendarsResult;
|
||||
if (Platform.isIOS) {
|
||||
calendarsResult = await _myPlugin.getCalendars();
|
||||
_completer!.complete(CalendarUtils._(calendarsResult));
|
||||
} else {
|
||||
calendarsResult = await deviceCalendarPlugin.retrieveCalendars();
|
||||
_completer!.complete(CalendarUtils._(calendarsResult.data));
|
||||
}
|
||||
} catch (e) {
|
||||
_completer!.completeError(e);
|
||||
}
|
||||
|
||||
return _completer!.future;
|
||||
}
|
||||
|
||||
Future createOrUpdateEvents({List<DateTime>? scheduleList, String? title, String? description, List<DateTime>? scheduleDateTime, List<DayOfWeek>? daysOfWeek}) async {
|
||||
tzl.initializeTimeZones();
|
||||
List<Event> events = [];
|
||||
Location _currentLocation;
|
||||
if (DateTime.now().timeZoneName == "+04")
|
||||
_currentLocation = getLocation('Asia/Dubai');
|
||||
else
|
||||
_currentLocation = getLocation('Asia/Riyadh');
|
||||
|
||||
scheduleDateTime!.forEach((element) {
|
||||
RecurrenceRule recurrenceRule = RecurrenceRule(
|
||||
// RecurrenceFrequency.Daily,
|
||||
// daysOfWeek: daysOfWeek,
|
||||
// endDate: element,
|
||||
until: element, frequency: Frequency.daily,
|
||||
);
|
||||
//added byAamir Tz Time
|
||||
Event event = Event(writableCalendars!.id,
|
||||
recurrenceRule: recurrenceRule,
|
||||
start: TZDateTime.from(element, _currentLocation),
|
||||
end: TZDateTime.from(element.add(Duration(minutes: 30)), _currentLocation),
|
||||
title: title,
|
||||
description: description);
|
||||
events.add(event);
|
||||
});
|
||||
|
||||
events.forEach((element) {
|
||||
deviceCalendarPlugin.createOrUpdateEvent(element);
|
||||
});
|
||||
}
|
||||
|
||||
Future createOrUpdateEvent({required String title, required String description, required String location, DateTime? scheduleDateTime, String? eventId}) async {
|
||||
RecurrenceRule recurrenceRule = RecurrenceRule(
|
||||
// RecurrenceFrequency.Daily,
|
||||
// daysOfWeek: daysOfWeek,
|
||||
// endDate: scheduleDateTime,
|
||||
until: scheduleDateTime, frequency: Frequency.daily,
|
||||
);
|
||||
|
||||
Location _currentLocation;
|
||||
// if (DateTime.now().timeZoneName == "+04")
|
||||
// _currentLocation = getLocation('Asia/Dubai');
|
||||
// else
|
||||
_currentLocation = getLocation('Asia/Riyadh');
|
||||
|
||||
TZDateTime scheduleDateTimeUTZ = TZDateTime.from(scheduleDateTime!, _currentLocation);
|
||||
|
||||
print("writableCalendars-name: " + writableCalendars.name);
|
||||
print("writableCalendars-Id: " + writableCalendars.id);
|
||||
print("writableCalendarsToString: " + writableCalendars.toString());
|
||||
print("writableCalendarsToString: " + writableCalendars!.id!);
|
||||
Event event = Event(
|
||||
writableCalendars!.id,
|
||||
start: scheduleDateTimeUTZ,
|
||||
end: scheduleDateTimeUTZ.add(Duration(minutes: 30)),
|
||||
title: title,
|
||||
description: description,
|
||||
);
|
||||
|
||||
ios.CalendarEvent iosCalEvent =
|
||||
ios.CalendarEvent(location: location, startDate: scheduleDateTimeUTZ, endDate: scheduleDateTimeUTZ.add(Duration(minutes: 30)), title: title, description: description, isAllDay: false);
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
Result<bool> result = await deviceCalendarPlugin.hasPermissions();
|
||||
print(result);
|
||||
await deviceCalendarPlugin.createOrUpdateEvent(event).catchError((e) {
|
||||
print("catchError " + e.toString());
|
||||
}).whenComplete(() {
|
||||
print("whenComplete Calender ID " + eventId!);
|
||||
});
|
||||
} else {
|
||||
await _myPlugin.createEvent(calendarId: writableCalendars.id!, event: iosCalEvent).catchError((e) {
|
||||
print("catchError " + e.toString());
|
||||
}).whenComplete(() {
|
||||
print("whenComplete Calender ID iOS " + eventId!);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteEvent(String _calendarId, String _eventId) async {
|
||||
if (Platform.isIOS) {
|
||||
await _myPlugin.deleteEvent(calendarId: _calendarId, eventId: _eventId);
|
||||
} else {
|
||||
await deviceCalendarPlugin.deleteEvent(_calendarId, _eventId);
|
||||
}
|
||||
}
|
||||
|
||||
Future retrieveEvents(
|
||||
String calendarId,
|
||||
RetrieveEventsParams retrieveEventsParams,
|
||||
) async {
|
||||
if (Platform.isIOS) {
|
||||
return await _myPlugin.getEvents(calendarId: calendarId);
|
||||
} else {
|
||||
return await deviceCalendarPlugin.retrieveEvents(calendarId, retrieveEventsParams);
|
||||
}
|
||||
}
|
||||
|
||||
Future createCalendar(
|
||||
String calendarName, {
|
||||
Color? calendarColor,
|
||||
String? localAccountName,
|
||||
}) async {
|
||||
return await deviceCalendarPlugin.createCalendar(calendarName, calendarColor: calendarColor, localAccountName: localAccountName);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<Permission, PermissionStatus>> requestPermissions() async {
|
||||
var permissionResults = [Permission.calendarFullAccess].request();
|
||||
return permissionResults;
|
||||
}
|
||||
|
||||
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 {
|
||||
if (Platform.isAndroid) {
|
||||
if (await PermissionService.isCalendarPermissionEnabled()) {
|
||||
_showReminderBottomSheet(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted,
|
||||
onSuccess: onSuccess, title: title, description: description, onMultiDateSuccess: onMultiDateSuccess, isMultiAllowed: isMultiAllowed);
|
||||
} 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, isMultiAllowed: isMultiAllowed);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
} else {
|
||||
if (await Permission.calendarWriteOnly.request().isGranted) {
|
||||
if (await Permission.calendarFullAccess.request().isGranted) {
|
||||
_showReminderBottomSheet(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted,
|
||||
onSuccess: onSuccess, title: title, description: description, onMultiDateSuccess: onMultiDateSuccess, isMultiAllowed: isMultiAllowed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
showCommonBottomSheetWithoutHeight(providedContext, title: "Set the timer of reminder", child: PrescriptionReminderView(
|
||||
setReminder: (int value) async {
|
||||
if (!isMultiAllowed!) {
|
||||
if (onMultiDateSuccess == null) {
|
||||
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
||||
await calendarUtils.createOrUpdateEvent(
|
||||
title: title ?? "You have appointment with Dr. $doctorName",
|
||||
description: description ?? "At $appoDateFormatted $appoTimeFormatted",
|
||||
scheduleDateTime: dateTime,
|
||||
eventId: eventId,
|
||||
location: '');
|
||||
onSuccess();
|
||||
}
|
||||
} else {
|
||||
onMultiDateSuccess!(value);
|
||||
}
|
||||
},
|
||||
), callBackFunc: () {}, isFullScreen: false);
|
||||
}
|
||||
|
||||
setCalender(BuildContext context,
|
||||
{required String eventId, required int selectedMinutes, int? frequencyNumber, required int days, required String orderDate, required String itemDescriptionN, required String route}) async {
|
||||
DateTime actualDate = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day, 8, 0);
|
||||
frequencyNumber ??= 2; //Some time frequency number is null so by default will be 2
|
||||
|
||||
int remainingDays = days - (Jiffy.parseFromDateTime(DateTime.now()).diff(Jiffy.parseFromDateTime(DateUtil.convertStringToDate(orderDate)), unit: Unit.day) as int);
|
||||
if (remainingDays.isNegative) {
|
||||
getIt.get<DialogService>().showErrorBottomSheet(message: "Prescription date has been already passed you can not add a reminder for this prescription.");
|
||||
return;
|
||||
}
|
||||
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
||||
|
||||
try {
|
||||
for (int i = 0; i < remainingDays; i++) {
|
||||
//event for number of days.
|
||||
for (int j = 0; j < frequencyNumber; j++) {
|
||||
// event for number of times per day.
|
||||
if (j != 0) {
|
||||
actualDate.add(new Duration(hours: 8)); // 8 hours addition for daily dose.
|
||||
}
|
||||
//Time subtraction from actual reminder time. like before 30, or 1 hour.
|
||||
|
||||
actualDate = Jiffy.parseFromDateTime(actualDate).subtract(minutes: selectedMinutes).dateTime;
|
||||
|
||||
calendarUtils.createOrUpdateEvent(
|
||||
title: "$itemDescriptionN} Prescription Reminder",
|
||||
description: "$itemDescriptionN $frequencyNumber $route ",
|
||||
scheduleDateTime: actualDate,
|
||||
eventId: eventId + (i.toString() + j.toString()),
|
||||
location: '', //event id with varitions
|
||||
);
|
||||
print("Creating event #$j for day $i → $actualDate");
|
||||
actualDate = DateTime(actualDate.year, actualDate.month, actualDate.day, 8, 0);
|
||||
}
|
||||
actualDate = Jiffy.parseFromDateTime(actualDate).add(days: 1).dateTime;
|
||||
}
|
||||
} catch (ex) {
|
||||
getIt.get<DialogService>().showErrorBottomSheet(message: "catch:$ex");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> checkAndRemove(hasReminder, {bool delete = false, String itemDescriptionN = ""}) async {
|
||||
final ios.CalendarPlugin _myPlugin = ios.CalendarPlugin();
|
||||
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
||||
DateTime startEventsDate = Jiffy.parseFromDateTime(DateTime.now()).subtract(days: 30).dateTime;
|
||||
DateTime endEventsDate = Jiffy.parseFromDateTime(DateTime.now()).add(days: 120).dateTime;
|
||||
RetrieveEventsParams params = RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
|
||||
|
||||
if (calendarUtils.calendars != null) {
|
||||
if (Platform.isAndroid) {
|
||||
await processEvents(calendarUtils.calendars, calendarUtils, params, delete, itemDescriptionN, hasReminder);
|
||||
} else {
|
||||
List<ios.Calendar>? iosCalendars = await _myPlugin.getCalendars();
|
||||
if (iosCalendars != null) {
|
||||
await processEvents(iosCalendars.map((cal) => Calendar(id: cal.id, name: cal.name, accountName: cal.accountName)).toList(), calendarUtils, params, delete, itemDescriptionN, hasReminder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> processEvents(List<Calendar> calendars, calendarUtils, params, delete, String itemDescriptionN, hasReminder) async {
|
||||
for (var calendar in calendars) {
|
||||
Result<UnmodifiableListView<Event>> events = await calendarUtils.retrieveEvents(calendar.id!, params);
|
||||
for (var event in events.data!) {
|
||||
if (event.title!.contains(itemDescriptionN)) {
|
||||
if (delete) {
|
||||
await calendarUtils.deleteEvent(calendar, event);
|
||||
// AppToast.showSuccessToast(message: TranslationBase.of(context).reminderCancelSuccess);
|
||||
hasReminder = false;
|
||||
} else {
|
||||
hasReminder = false;
|
||||
// setState(() {
|
||||
// hasReminder = true;
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,36 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hmg_patient_app_new/services/cache_service.dart';
|
||||
import 'package:hmg_patient_app_new/theme/colors.dart';
|
||||
|
||||
class ProfileSettingsViewModel extends ChangeNotifier {
|
||||
static const String _darkModeKey = 'is_dark_mode';
|
||||
|
||||
void notify(){
|
||||
final CacheService _cacheService;
|
||||
|
||||
bool _isDarkMode = false;
|
||||
|
||||
bool get isDarkMode => _isDarkMode;
|
||||
|
||||
ProfileSettingsViewModel({required CacheService cacheService})
|
||||
: _cacheService = cacheService;
|
||||
|
||||
/// Call once at app startup (before the first frame) to restore the
|
||||
/// persisted dark-mode preference.
|
||||
void loadDarkMode() {
|
||||
final saved = _cacheService.getBool(key: _darkModeKey);
|
||||
_isDarkMode = saved ?? false;
|
||||
AppColors.isDarkMode = _isDarkMode;
|
||||
// No notifyListeners() here — we are called before build.
|
||||
}
|
||||
|
||||
void toggleDarkMode(bool value) {
|
||||
_isDarkMode = value;
|
||||
AppColors.isDarkMode = value;
|
||||
_cacheService.saveBool(key: _darkModeKey, value: value);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void notify() {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||