Search code examples
flutterfiledartpathfilepath

Flutter File.toString without 'File:...' to share image


Trying to get the file path to a string to share but when I print it is starting with 'File: ...'

Is there another method besides toString that I should be using to get the same path without these characters?

List<String> sharableFile = List<String>();

  void shareFile() {
    print(path.basename(photos[0].name.toString()))
    print(photos[0].name.toString());
    sharableFile.add(photos[0].name.toString());
    Share.shareFiles(sharableFile);
  }

output of the two print statements are:

flutter: IMG_0005.JPG'

flutter: File: '/Users/firstlast/Library/Developer/CoreSimulator/Devices/9A654C10-BD7B-4D39-8BDB-A47E8D0C1AF6/data/Media/DCIM/100APPLE/IMG_0005.JPG'


Solution

  • If you want the File's path, just use its path property instead of calling toString() on it.

    Note that if you want an absolute path, you might need to use use the absolute property to get an absolute version of the File object first.