Integrate app events with device_calendar package

Hi, I am trying to integrate my app with the users local device calendar and am having some issues. I have gone down the path of creating a custom action that, when given the userId (button submit), will execute all the logic to find matching events, update existing ones and create new events in the users app profile where there is no match already. I believe I have the logic for the code but am unable to save the action due to the following error "Action "calendarSync" declaration not found." I am able to compile the code without any issues now, but can't save...

My initial thoughts are that the device_calendar package (which seems poorly documented from what I can find https://pub.dev/packages/device_calendar), requires changes to the main.dart file as it it accessing the local calendar application on either android or apple devices.

Or, I am missing something and I have not structured my class, CalendarSyncService, correctly. Any help would be hugely appreciated! Here is a snippet of the code that I believe is causing the error.

import 'package:device_calendar/device_calendar.dart';
import 'package:timezone/data/latest.dart' as tzdata;
import 'package:timezone/timezone.dart' as tz;

class CalendarSyncService {
  final DeviceCalendarPlugin _deviceCalendarPlugin;
  final String ukTimeZone = 'Europe/London';
  final supabase = SupaFlow.client;

  CalendarSyncService() : _deviceCalendarPlugin = DeviceCalendarPlugin() {
    tzdata.initializeTimeZones(); // Initialize timezones
    tz.setLocalLocation(tz.getLocation(ukTimeZone)); // Set the local timezone
  }

  Future<String> calendarSync(String userId) async {
    if (!await _checkAndRequestPermissions()) {
      return 'Calendar permission denied';
    }

    final invitations = await getInvitationsFromYourDatabase(userId);
    if (invitations.isEmpty) {
    return 'No invitations found';
    }
    final eventDetailsMap = await getEventDetailsForInvitations(invitations);
    if (eventDetailsMap.isEmpty) {
    return 'No event details found for invitations';
    }

    var calendarsResult = await _deviceCalendarPlugin.retrieveCalendars();
    if (calendarsResult.isSuccess != true || calendarsResult.data == null) {
      return 'Failed to retrieve calendars';
    }
1
2 replies