gather method

  1. @override
Future<List<ICloudFile>> gather({
  1. required String containerId,
  2. StreamHandler<List<ICloudFile>>? onUpdate,
})
override

Gather all the files' meta data from iCloud container.

containerId is the iCloud Container Id.

onUpdate is an optional paramater can be used as a call back every time when the list of files are updated. It won't be triggered when the function initially returns the list of files.

The function returns a future of list of ICloudFile.

Implementation

@override
Future<List<ICloudFile>> gather({
  required String containerId,
  StreamHandler<List<ICloudFile>>? onUpdate,
}) async {
  final eventChannelName = onUpdate == null
      ? ''
      : _generateEventChannelName('gather', containerId);

  if (onUpdate != null) {
    await methodChannel.invokeMethod(
        'createEventChannel', {'eventChannelName': eventChannelName});

    final gatherEventChannel = EventChannel(eventChannelName);
    final stream = gatherEventChannel
        .receiveBroadcastStream()
        .where((event) => event is List)
        .map<List<ICloudFile>>((event) => _mapFilesFromDynamicList(
            List<Map<dynamic, dynamic>>.from(event)));

    onUpdate(stream);
  }

  final mapList =
      await methodChannel.invokeListMethod<Map<dynamic, dynamic>>('gather', {
    'containerId': containerId,
    'eventChannelName': eventChannelName,
  });

  return _mapFilesFromDynamicList(mapList);
}