readFile method

Future<String> readFile(
  1. String fileName, {
  2. String? package,
})

Reads a file from the assets.

The fileName is the full path of the asset. When a package is given, the path is resolved relative to that package's assets.

Implementation

Future<String> readFile(String fileName, {String? package}) async {
  final path = _resolve(fileName, package);
  if (!_files.containsKey(path)) {
    _files[path] = await _readFile(path);
  }
  assert(
    _files[path] is _StringAsset,
    '"$path" was previously loaded as a binary file',
  );
  return (_files[path]! as _StringAsset).value;
}