How to load an image from intent in Flutter? How to load an image from intent in Flutter? dart dart

How to load an image from intent in Flutter?


As you say, the resource permissions are bundled with the Intent. However, this should be transparent to you as you should be able to obtain an InputStream using (in MainActivity):

InputStream inputStream = getContentResolver().openInputStream(imageUri);

As the permission is only valid for the lifetime of the Intent, you should probably use this InputStream to immediately read the file, either into memory or a temporary file owned by your own app (depending on the size of photo).

Once the Widget is rendered, you can request the byte array or filename through the MethodChannel, and, in Flutter, use the Image.memory or Image.file constructors to create an Image Widget.

If using the temporary file method, use getCacheDir() in Java to find the cache folder. Create your own temporary file name, and copy the file. On the Flutter side, use package:path_provider - getTemporaryDirectory() to find the same directory. Just pass the filename across the MethodChannel.