fromJson static method

SchemaComponent fromJson(
  1. Map<String, dynamic> json,
  2. String path, [
  3. int depth = 0
])

Implementation

static SchemaComponent fromJson(
  Map<String, dynamic> json,
  String path, [
  int depth = 0,
]) {
  if (depth > maxDepth) {
    throw SchemaFormatException(
      path,
      'schema is nested too deeply — more than $maxDepth levels',
    );
  }

  final type = req<String>(json, 'type', path);
  final common = _CommonProperties.fromJson(json, type);

  return switch (type) {
    'text' ||
    'textarea' ||
    'email' ||
    'password' => TextComponent._fromJson(json, common),
    'number' => NumberComponent._fromJson(json, common, path),
    'select' ||
    'multiselect' ||
    // The config shape is identical to `select` — Radio shares Select's
    // `Concerns\HasOptions` server-side (measured in vendor) — so one
    // model class serves all three; only the widget differs. See
    // RadioFieldWidget.
    'radio' => SelectComponent._fromJson(json, common, path),
    'toggle_buttons' => ToggleButtonsComponent._fromJson(json, common, path),
    'slider' => SliderComponent._fromJson(json, common, path),
    'toggle' || 'checkbox' => BooleanComponent._fromJson(json, common),
    // `time` shares the model — TimePicker inherits every accessor the
    // walker reads for `datetime` — but not the bound parse: see
    // DateComponent.parseTime.
    'date' ||
    'datetime' ||
    'time' => DateComponent._fromJson(json, common, path),
    'color' => ColorComponent._fromJson(json, common, path),
    'file' => FileComponent._fromJson(json, common, path),
    'tags' => TagsComponent._fromJson(json, common, path),
    'keyvalue' => KeyValueComponent._fromJson(json, common, path),
    'map_point' ||
    'map_point_entry' => MapPointComponent._fromJson(json, common, path),
    'phone' => PhoneComponent._fromJson(json, common),
    'repeater' => RepeaterComponent._fromJson(json, common, path, depth),
    'section' ||
    'grid' ||
    'tabs' ||
    'fieldset' => LayoutComponent._fromJson(json, common, path, depth),
    'text_entry' ||
    'badge_entry' ||
    'image_entry' ||
    'boolean_entry' ||
    'date_entry' ||
    'rich_entry' ||
    // Spatie's read-only tags entry. Same `List<String>` wire shape the
    // `tags` field's value already has — see `EntryRegistry`'s
    // `EntryKind.tags` branch, which reads it straight off the record.
    'tags_entry' => EntryComponent._fromJson(json, common, path),
    _ => UnknownComponent._fromJson(json, common, path, depth),
  };
}