decodeBoxConstraints static method

BoxConstraints? decodeBoxConstraints(
  1. dynamic value, {
  2. bool validate = true,
})

Decodes the given value into a BoxConstraints. If the value is null then null will be returned. Otherwise, this expects a Map like value that in JSON would look like:

{
  "maxHeight": <double>,
  "maxWidth": <double>,
  "minHeight": <double>,
  "minWidth": <double>
}

Implementation

static BoxConstraints? decodeBoxConstraints(
  dynamic value, {
  bool validate = true,
}) {
  BoxConstraints? result;

  if (value is BoxConstraints) {
    result = value;
  } else if (value != null) {
    assert(SchemaValidator.validate(
      schemaId: '$_baseSchemaUrl/box_constraints',
      value: value,
      validate: validate,
    ));
    result = BoxConstraints(
      maxHeight: JsonClass.parseDouble(value['maxHeight'], double.infinity)!,
      maxWidth: JsonClass.parseDouble(value['maxWidth'], double.infinity)!,
      minHeight: JsonClass.parseDouble(value['minHeight'], 0)!,
      minWidth: JsonClass.parseDouble(value['minWidth'], 0)!,
    );
  }

  return result;
}