ThemeSpec.fromJson constructor

ThemeSpec.fromJson(
  1. Object? json
)

Implementation

factory ThemeSpec.fromJson(Object? json) {
  final j = _map(json, 'ThemeSpec');
  final format = _int(j, 'format');
  if (format != jsonFormat) {
    throw FormatException('Unsupported ThemeSpec format $format');
  }
  final familyId = _int(j, 'family');
  final family = ThemeFamily.fromId(familyId);
  if (family == null) throw FormatException('Unknown family $familyId');
  return ThemeSpec(
    seed: _int(j, 'seed'),
    family: family,
    engineVersion: _int(j, 'engineVersion'),
    variant: _enumByName(ThemeVariant.values, j['variant'], 'variant'),
    heroId: _intOrNull(j, 'heroId'),
    seedHueTenths: _intOrNull(j, 'seedHueTenths'),
    intent: j['intent'] == null ? null : ThemeIntent.fromJson(j['intent']),
    intentCentred: j['intentCentred'] == true,
    brightness: _enumByName(
      ThemeBrightness.values,
      j['brightness'],
      'brightness',
    ),
    accessible: _bool(j, 'accessible'),
    palette: Palette.fromJson(j['palette']),
    keyShape: KeyShapeSpec.fromJson(j['keyShape']),
    keyStyle: KeyStyleSpec.fromJson(j['keyStyle']),
    type: TypeSpec.fromJson(j['type']),
    background: BackgroundSpec.fromJson(j['background']),
    motion: MotionSpec.fromJson(j['motion']),
    effects: EffectsSpec.fromJson(j['effects']),
    sound: _enumByName(SoundPackId.values, j['sound'], 'sound'),
    name: _str(j, 'name'),
    nonColourOperatorCue: _enumByName(
      OperatorCue.values,
      j['nonColourOperatorCue'],
      'operator cue',
    ),
  );
}