superlistapp / super_native_extensions

Native drag & drop, clipboard access and context menu.
MIT License
477 stars 87 forks source link

Cannot get the path of a dropped directory from Finder #418

Open rohintonc opened 3 months ago

rohintonc commented 3 months ago

This probably also applies to other platforms, as the limitation is due to an inaccessible private interface which can actually provide the directory path. You can either include the following private files:

import 'package:super_clipboard/src/reader_value.dart';
import 'package:super_native_extensions/src/native/virtual_file.dart';

final adapter = (reader as DataReaderVirtualFileAdapter);
final virtualFile = (adapter.file as VirtualFileFromFile);
final directoryPath = virtualFile.file.path;  

Or you can dispense with the private imports:

      try {
        final path = (reader as dynamic).file.file.path;
        if (!kIsWeb && FileSystemEntity.isDirectorySync(path)) {
          ... // can perform folder operations
        } else {
          ... // can get file bytes          
        }
      } catch (_) {}
knopp commented 3 months ago

Have you tried getting the fileUri value from the Reader? This seems like doing lot of unnecessary work just to get the URI.

rohintonc commented 3 months ago

@knopp I cannot see how to do that. Do you have any code example? I am using: super_clipboard: ^0.8.19 super_drag_and_drop: ^0.8.19

I cannot see any fileUri function or property for example on Reader. I have a feeling this was previously available in an earlier version of the package, but has now been moved into private classes.