0

I have a sound file in asset folder and I can check if it exist using code like below:

    if (FileSystemEntity.typeSync(
        '/Users/admin/Library/Developer/CoreSimulator/Devices/AC8BED2E-4EF1-4777-A399-EBD52E38B5C7/data/Containers/Data/Application/1390EE2C-A5D8-46E0-A414-AAC2B83CD20C/Library/Caches/sounds/3/unbeaten.m4a') !=
    FileSystemEntityType.notFound) {
  print('file is found');
} else {
  print('not found');
}

As you can see I need to use the absolute path. Is there a way to check if the file is in the asset folder using path like 'assets/sounds/3/unbeaten.m4a' without the need to specify the whole path?

Daryl Wong
  • 2,023
  • 5
  • 28
  • 61
  • Did you try with the `path_provider` library already? – Frank Treacy Dec 28 '19 at 15:44
  • Check these two questions... The asset manifest lets you find out the complete list of assets available. https://stackoverflow.com/questions/50998573/flutter-how-to-store-and-access-files-with-assetbundle https://stackoverflow.com/questions/56369100/how-do-i-get-an-array-list-filled-with-all-the-image-paths-i-loaded-as-assets-in/56369329#56369329 – Richard Heap Dec 28 '19 at 16:42

1 Answers1

0

As was mentioned by @frank06, by using path_provider, I am able to check if a file is in asset folder or not by using the following code. But this works for iOS only and I am still trying to find a solution for Android. Notice the need to add /Library and /Caches for iOS. For Android, it seems that I can't see the path unlike that of iOS.

I would appreciate it if anyone could provide me some info for that of Android. The appDir looks like this for Android - /data/user/0/com.learnchn.alsospeak/app_flutter/

directory = await getApplicationDocumentsDirectory();
var parent = directory.parent;

var directoryPath = directory.path;
var parentPath = parent.path;

String testString = 'sounds/3/unbeaten.m4a';

parentPath = parentPath + '/Library' '/Caches/' '$testString';
Daryl Wong
  • 2,023
  • 5
  • 28
  • 61