Flutter MacOs access to files

5.1k Views Asked by At

I'm trying to build app a custom desktop app in Flutter to be able to load pictures, like a gallery. To do so, I will ask to the user to pick a folder, and automatically it should show the pictures.

Now, starting from simple things, since it's first time developing for Mac, I'm just trying to display a picture via Image.file(new File) method.

The issue that I got back is 

======== Exception caught by image resource service ================================================
The following FileSystemException was thrown resolving an image codec:
Cannot open file, path = 'media/preview.jpg' (OS Error: Operation not permitted, errno = 1)

I'm thinking somehow is related to the entitlements. What I have on my entitlements is:

<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.assets.downloads.read-write</key>
<true/>
<key>com.apple.security.assets.pictures.read-write</key>
<true/>
<key>com.apple.security.assets.downloads.read-write</key>
<true/>

But since the folder from where I want to load the pictures could be anywhere, I wonder if this is the reason why I get the error.

3

There are 3 best solutions below

2
On BEST ANSWER

So it seems that as long as your app is in the sandbox it looks like it can only open files outside of those folders (Downloads, Pictures, Music, and Movies) if the user selects them from an open dialog.

So for development purpouse I've disabled the sandboxing, conscious of the fact I could not distribute on the Apple Store.

But at least I can develop. Enjoy

0
On

I met the same issue and tackled it by disabling com.apple.security.app-sandbox in example/macos/Runner/DebugProfile.entitlements:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <false/>
</dict>
</plist>

0
On

i couldn't access to files which is located in external. But its worked for me thank you so much...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <false/>
</dict>
</plist>