chooseInstead method

Future<DVDropEvent?> chooseInstead({
  1. bool multiple = true,
  2. String type = 'any',
})

Where a target has no drag and drop, the same files arrive by choosing them: opens the file picker and delivers the choice as a drop, to the window handler and the dropped stream. Returns the event, or null when nothing was chosen.

Implementation

Future<DVDropEvent?> chooseInstead({
  bool multiple = true,
  String type = 'any',
}) async {
  Object? chosen;
  if (DVNativeBridge.isRegistered('dialogs.openFile')) {
    chosen = await DVNativeBridge.require<Object?>(
      'dialogs.openFile',
      <String, Object?>{'multiple': multiple},
    );
  } else {
    chosen = await DVNativeBridge.require<List<Object?>>(
      'media.pick',
      <String, Object?>{'type': type, 'multiple': multiple},
    );
  }
  final List<Object?> items = chosen is List
      ? chosen
      : (chosen == null ? const <Object?>[] : <Object?>[chosen]);
  final DVDropEvent event = DVDropEvent.fromMap(<String, Object?>{
    'files': <Object?>[
      for (final Object? item in items)
        if (item is String)
          <String, Object?>{'path': item}
        else if (item is Map)
          item,
    ],
  });
  if (event.isEmpty) return null;
  _onDrop?.call(event);
  _dropped.add(event);
  return event;
}