createCalendar method

Future<Result<String>> createCalendar(
  1. String? calendarName, {
  2. Color? calendarColor,
  3. String? localAccountName,
})

Creates a new local calendar for the current device.

The calendarName parameter is the name of the new calendar
The calendarColor parameter is the color of the calendar. If null, a default color (red) will be used
The localAccountName parameter is the name of the local account:

  • Android Required. If localAccountName parameter is null or empty, it will default to 'Device Calendar'. If the account name already exists in the device, it will add another calendar under the account, otherwise a new local account and a new calendar will be created.
  • iOS Not used. A local account will be picked up automatically, if not found, an error will be thrown.

Returns a Result with the newly created Calendar.id

Implementation

Future<Result<String>> createCalendar(
  String? calendarName, {
  Color? calendarColor,
  String? localAccountName,
}) async {
  return _invokeChannelMethod(
    ChannelConstants.methodNameCreateCalendar,
    assertParameters: (result) {
      calendarColor ??= Colors.red;

      _assertParameter(
        result,
        calendarName?.isNotEmpty == true,
        ErrorCodes.invalidArguments,
        ErrorMessages.createCalendarInvalidCalendarNameMessage,
      );
    },
    arguments: () => <String, Object?>{
      ChannelConstants.parameterNameCalendarName: calendarName,
      ChannelConstants.parameterNameCalendarColor:
          '0x${calendarColor?.value.toRadixString(16)}',
      ChannelConstants.parameterNameLocalAccountName:
          localAccountName?.isEmpty ?? true
              ? 'Device Calendar'
              : localAccountName
    },
  );
}