import 'package:app_client/shared/models/video_asset_preview.dart'; import 'package:intl/intl.dart'; class CalendarHelpers{ static String _formatDateTime(DateTime dateTime) { final DateFormat formatter = DateFormat('yyyyMMddTHHmmss'); return '${formatter.format(dateTime)}Z'; } static String createICalString(VideoAssetPreview mediaAsset){ String eventName = mediaAsset.name; DateTime eventStart = mediaAsset.localStartTime; DateTime eventEnd = mediaAsset.localStartTime.add(const Duration(minutes: 30)); String location = mediaAsset.providerName; // Create the iCal content final StringBuffer icalContent = StringBuffer() ..writeln('BEGIN:VCALENDAR') ..writeln('VERSION:2.0') ..writeln('PRODID:-//Xfinity//Xfinity Rewards//EN') ..writeln('BEGIN:VEVENT') ..writeln('UID:${DateTime.now().millisecondsSinceEpoch}@comcast.com') ..writeln('DTSTAMP:${_formatDateTime(DateTime.now().toUtc())}') ..writeln('DTSTART:${_formatDateTime(eventStart.toUtc())}') ..writeln('DTEND:${_formatDateTime(eventEnd.toUtc())}') ..writeln('LOCATION:$location') ..writeln('SUMMARY:$eventName') ..writeln('END:VEVENT') ..writeln('END:VCALENDAR'); return icalContent.toString().trim().replaceAll('\n', '\r\n'); } } // void addCalendarEvent(String calendarString) { // Convert the iCal content to a Blob final bytes = utf8.encode(calendarString); final blob = Blob([bytes], 'text/calendar'); // Create a URL for the Blob final url = Url.createObjectUrlFromBlob(blob); //Create an anchor element and set its href to the Blob URL final anchor = AnchorElement(href: url) ..setAttribute('download', 'event.ics') ..click(); //Revoke the Blob URL to free up memory Url.revokeObjectUrl(url); }