readJson method

Future<Map<String, dynamic>> readJson(
  1. String fileName, {
  2. String? package,
})

Reads a json 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<Map<String, dynamic>> readJson(
  String fileName, {
  String? package,
}) async {
  final path = _resolve(fileName, package);
  if (!_files.containsKey(path)) {
    _files[path] = await _readJson(path);
  }
  assert(
    _files[path] is _JsonAsset,
    '"$path" was previously loaded as a different type',
  );
  return (_files[path]! as _JsonAsset).value;
}