TypeAlias.fromJson constructor

TypeAlias.fromJson(
  1. Object? json
)

"to" may name a variant after the type (Button.primary).

Implementation

factory TypeAlias.fromJson(Object? json) {
  final m = json is String ? {'to': json} : readMap(json) ?? const <String, Object?>{};
  final to = readString(m['to']);
  final dot = to?.indexOf('.') ?? -1;
  return TypeAlias(
    to: dot < 0 ? to : to!.substring(0, dot),
    variant: dot < 0 ? null : to!.substring(dot + 1),
    add: readString(m['add']),
    requires: [
      for (final k in (m['requires'] as List?) ?? const <Object?>[])
        if (k is String) k,
    ],
    parameters: {
      for (final e in (readMap(m['parameters']) ?? const <String, Object?>{}).entries)
        if (e.value is String) e.key: e.value! as String,
    },
  );
}