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.maybeParseDouble(value['maxHeight']) ?? double.infinity,
      maxWidth:
          JsonClass.maybeParseDouble(value['maxWidth']) ?? double.infinity,
      minHeight: JsonClass.maybeParseDouble(value['minHeight']) ?? 0.0,
      minWidth: JsonClass.maybeParseDouble(value['minWidth']) ?? 0.0,
    );
  }

  return result;
}