value property

String? get value

Gets the CSS value of the EdgeInsets.

If padding properties are set, it returns the padding value. Otherwise, it returns the margin value.

Returns null if both padding and margin properties are not set.

Example:

const EdgeInsets.only(top: 10, right: 20, bottom: 30, left: 40).value;
// Returns '10px 20px 30px 40px'

Implementation

String? get value {
  final map = pProps.isEmpty ? mProps : pProps;
  if (map.isEmpty) return null;

  if (map['padding'] != null) return map['padding'];
  if (map['margin'] != null) return map['margin'];

  String value = '';

  final pTop = map['padding-top'];
  final pRight = map['padding-right'];
  final pBottom = map['padding-bottom'];
  final pLeft = map['padding-left'];

  final mTop = map['margin-top'];
  final mRight = map['margin-right'];
  final mBottom = map['margin-bottom'];
  final mLeft = map['margin-left'];

  if (pTop != null) value += '$pTop ';
  if (pRight != null) value += '$pRight ';
  if (pBottom != null) value += '$pBottom ';
  if (pLeft != null) value += '$pLeft ';

  if (mTop != null) value += '$mTop ';
  if (mRight != null) value += '$mRight ';
  if (mBottom != null) value += '$mBottom ';
  if (mLeft != null) value += '$mLeft ';

  return value.trim();
}