list method
returns a list of assets located under the given root
directory.
The root
directory must be relative to the parent of
the 'asset' directory.
.e.g. Assets live under lib/src/assets
If you have asssets lib/src/assets/templates/fred.txt lib/src/assets/templates/tom.txt
The call
var templates = Assets.list(root: 'assets/templates');
Will return a list of fully qualified paths to those assets on your local file system.
The pattern
is a wildcard (glob) that controls what files are returned.
The root
is the directory to start searching from. It MUST start with assets/.
If it doesn't start with assets/ an ArgumentError will be thrown.
Specify recursive
= true if you want the list command to
recursively search all
directories under root
.
Implementation
List<String?> list(String pattern,
{required String root, bool recursive = false}) {
if (!root.startsWith('assets/')) {
throw ArgumentError('The root must start with assets/');
}
return find(pattern,
workingDirectory: _resolveAssetPath(root), recursive: recursive)
.toList();
}