fromJson static method

TextToImageRequestBody? fromJson(
  1. dynamic value
)

Returns a new TextToImageRequestBody instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static TextToImageRequestBody? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      for (var key in requiredKeys) {
        assert(json.containsKey(key),
            'Required key "TextToImageRequestBody[$key]" is missing from JSON.');
        assert(json[key] != null,
            'Required key "TextToImageRequestBody[$key]" has a null value in JSON.');
      }
      return true;
    }());

    return TextToImageRequestBody(
      height: mapValueOfType<int>(json, r'height') ?? 512,
      width: mapValueOfType<int>(json, r'width') ?? 512,
      textPrompts: TextPrompt.listFromJson(json[r'text_prompts']),
      cfgScale: json[r'cfg_scale'] == null
          ? 7
          : num.parse(json[r'cfg_scale'].toString()),
      clipGuidancePreset:
          ClipGuidancePreset.fromJson(json[r'clip_guidance_preset']),
      sampler: Sampler.fromJson(json[r'sampler']),
      samples: mapValueOfType<int>(json, r'samples') ?? 1,
      seed: mapValueOfType<int>(json, r'seed') ?? 0,
      steps: mapValueOfType<int>(json, r'steps') ?? 50,
      stylePreset: StylePreset.fromJson(json[r'style_preset']),
      extras: mapValueOfType<Object>(json, r'extras'),
    );
  }
  return null;
}