1

How do I get last picture from gallery (camera roll) using flutter?

I would like to display this photo as a thumbnail like this:

enter image description here

I know that it's possible in android Get uri of picture taken by camera and in IOS Swift - how to get last taken 3 photos from photo library?

Is there a tool, lib, media API that could help me with that?

Adelina
  • 10,915
  • 1
  • 38
  • 46

3 Answers3

3

You can try using this library. photo_manager

  List<AssetEntity> assets = [];
  _fetchAssets() async {
    final albums = await PhotoManager.getAssetPathList(type: RequestType.all);
    final recentAlbum = albums.first;
    final recentAssets = await recentAlbum.getAssetListRange(
      start: 0, // start at index 0
      end: 1, // end at a very big index (to get all the assets)
    );
    print(recentAssets);

    setState(() => assets = recentAssets);
  }
0

Use platform channels ,, as you know it's native solution

https://medium.com/flutter-io/flutter-platform-channels-ce7f540a104e

https://flutter.io/docs/development/platform-integration/platform-channels

Saifallak
  • 1,234
  • 2
  • 13
  • 28
0

If you're willing to do this through a dialog, you can use the image picker plugin which allows you to go through the camera's image gallery and the user can select the image (including the last image).

If you want this done completely programmatically, someone implemented a pull request for this very feature here: https://github.com/flutter/plugins/pull/676, but it hasn't been accepted because it needs some tests. You could copy the code from that PR, or add some tests, and then get it accepted into the repo!

fortuna
  • 1,176
  • 1
  • 8
  • 8