gather method
Future<GatherResult>
gather({
- required String containerId,
- StreamHandler<
GatherResult> ? 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.
When onUpdate is provided, the update stream stays active until the
subscription is canceled. Callers should dispose listeners when done.
The function returns a GatherResult containing parsed files and any invalid entries.
Implementation
@override
Future<GatherResult> gather({
required String containerId,
StreamHandler<GatherResult>? onUpdate,
}) async {
final eventChannelName = onUpdate == null
? ''
: _generateEventChannelName('gather', containerId);
if (onUpdate != null) {
await _invokeMethod<void>(
'createEventChannel',
{'eventChannelName': eventChannelName},
);
final gatherEventChannel = EventChannel(eventChannelName);
final stream = gatherEventChannel
.receiveBroadcastStream()
.where((event) => event is List)
.map<GatherResult>((event) {
return _mapFilesFromDynamicList(event as List);
});
onUpdate(stream);
}
final mapList = await _invokeListMethod<dynamic>('gather', {
'containerId': containerId,
'eventChannelName': eventChannelName,
});
return _mapFilesFromDynamicList(mapList);
}