getCalendarAccounts method

  1. @override
Future<List<CalendarAccount>?> getCalendarAccounts()
override

Implementation

@override
Future<List<CalendarAccount>?> getCalendarAccounts() async {
  try {
    final list = await methodChannel
        .invokeMethod<List<dynamic>?>('getCalendarAccounts');
    if (list != null && list.isNotEmpty) {
      List<CalendarAccount> calendarList = <CalendarAccount>[];
      for (dynamic map in list) {
        var calendarId = map['calendarId'] as String;
        var accountName = map["accountName"] as String;
        var accountType = map["accountType"] as String;
        IosAccountParams? iosAccountParams;
        AndroidAccountParams? androidAccountParams;

        if (Platform.isIOS) {
          var sourceId = map["sourceId"] as String;
          var sourceTitle = map["sourceTitle"] as String;
          var sourceType = map["sourceType"] as String;
          iosAccountParams =
              IosAccountParams(sourceId, sourceType, sourceTitle);
        } else if (Platform.isAndroid) {
          var isPrimary = map["isPrimary"] as int;
          var displayName = map["displayName"] as String?;
          var ownerAccount = map["ownerAccount"] as String?;
          var name = map["name"] as String?;
          androidAccountParams = AndroidAccountParams(
              isPrimary == 1, displayName ?? '', ownerAccount ??'', name ??'');
        }

        calendarList.add(CalendarAccount(calendarId, accountName, accountType,
            androidAccountParams: androidAccountParams,
            iosAccountParams: iosAccountParams));
      }
      return calendarList;
    }
  } on Exception catch (e) {
    if (kDebugMode) {
      print(e.toString());
    }
  }
  return null;
}