decodeEdgeInsetsDirectional static method

EdgeInsetsDirectional? decodeEdgeInsetsDirectional(
  1. dynamic value, {
  2. bool ltr = true,
  3. bool validate = true,
})

Decodes the value into an EdgeInsetsGeometry.

If the value is a String, double, or int then this will parse the number and pass it to EdgeInsets.all.

If the value is an array with two entities, this call EdgeInsets.symmetric with the first element passed as the horizontal and the second as the vertical.

If the value is an array with four entities, this call EdgeInsets.fromLTRB passing each element in order.

Finally, this may be a Map-like structure in the following JSON format:

{
  "bottom": "<double>",
  "end": "<double>",
  "start": "<double>",
  "top": "<double>"
}

Implementation

static EdgeInsetsDirectional? decodeEdgeInsetsDirectional(
  dynamic value, {
  bool ltr = true,
  bool validate = true,
}) {
  EdgeInsetsDirectional? result;
  final decoded = decodeEdgeInsetsGeometry(value, validate: validate);

  if (decoded is EdgeInsets) {
    result = EdgeInsetsDirectional.only(
      bottom: decoded.bottom,
      end: ltr ? decoded.right : decoded.left,
      start: ltr ? decoded.left : decoded.right,
      top: decoded.top,
    );
  } else if (decoded is EdgeInsetsDirectional) {
    result = decoded;
  }

  return result;
}