load static method

Future<SyniPersona> load(
  1. String id
)

Resolve and parse the bundled persona JSON for id. Throws SyniSpecPersonaException when the id is unknown or the JSON can't be projected onto SyniPersona.

Implementation

static Future<SyniPersona> load(String id) async {
  final assetPath = 'packages/syni/assets/personas/prod/$id.json';
  final String raw;
  try {
    raw = await rootBundle.loadString(assetPath);
  } catch (e) {
    throw SyniSpecPersonaException(
      'persona "$id" not bundled at $assetPath',
      cause: e,
    );
  }

  final Map<String, dynamic> json;
  try {
    json = jsonDecode(raw) as Map<String, dynamic>;
  } catch (e) {
    throw SyniSpecPersonaException('persona "$id": invalid JSON', cause: e);
  }

  return _fromJson(json);
}