file_open 0.1.0
file_open: ^0.1.0 copied to clipboard
A plugin to receive file open events on macOS
file_open #
Flutter plugin to receive file open events on macOS.
Requirements #
- macOS 10.15 or later
API #
FileOpen.onOpened: Stream of lists of URIs opened by the user. Each event contains one or more URIs.FileOpen.setLoggingEnabled(bool): Enable or disable logging on the native platform. Logging is enabled by default.
Important Notes #
The FileOpen instance is lazily created.
To receive initial file open events that launched the app,
ensure to access FileOpen.onOpened or call any methods early in your app's lifecycle,
such as in main() or during widget initialization.
Accessing it too late may miss the initial files.
Platform Setup #
macOS #
To handle file open events, configure your app's Info.plist with the appropriate keys:
- CFBundleDocumentTypes: Declares the document types your app can open. Each entry specifies file extensions, MIME types, and Uniform Type Identifiers (UTIs). This tells macOS which files your app can handle, triggering open events when users double-click or open such files. See Apple's documentation for details.
- CFBundleURLTypes: Declares URL schemes your app can handle, such as custom protocols (e.g.,
myapp://). When URLs with these schemes are opened, the app receives the event. See Apple's documentation for details. - UTExportedTypeDeclarations: Declares custom UTIs that your app defines and exports. Use this when your app creates its own file types not covered by standard system UTIs, allowing other apps to recognize and potentially open them. See Apple's documentation for details.
Example #
The example app in this repository demonstrates registering a custom file extension .abcde
in its Info.plist to handle file open events.