flutterdartflutter-pluginflutter-imageflutter-file

Flutter Image gallery saver - how to access path


I'm using Image gallery saver plugin for saving images. Method

await ImageGallerySaver.saveImage(pngBytes)

returns an object

{filePath: file:///storage/emulated/0/wallpapers/1608205629471.jpg, errorMessage: null, isSuccess: true}

I'd like to get the path of the newly saved file (/storage/emulated/0/wallpapers/1608205629471.jpg).

Is there a way to achieve that?


Solution

  • That is a Map object. Access the filePath String like so:

    var response = await ImageGallerySaver.saveImage(pngBytes);
    
    // value = json['key']
    var path = response['filePath']; // 'file:///storage/emulated/0/wallpapers/1608205629471.jpg'