withMargin method

Widget withMargin({
  1. double? top,
  2. double? bottom,
  3. double? left,
  4. double? right,
  5. double? horizontal,
  6. double? vertical,
  7. double? all,
})

Implementation

Widget withMargin(
    {double? top,
    double? bottom,
    double? left,
    double? right,
    double? horizontal,
    double? vertical,
    double? all}) {
  assert(() {
    if (all != null) {
      if (top != null ||
          bottom != null ||
          left != null ||
          right != null ||
          horizontal != null ||
          vertical != null) {
        throw FlutterError(
            'All margin properties cannot be used with other margin properties.');
      }
    } else if (horizontal != null) {
      if (left != null || right != null) {
        throw FlutterError(
            'Horizontal margin cannot be used with left or right margin.');
      }
    } else if (vertical != null) {
      if (top != null || bottom != null) {
        throw FlutterError(
            'Vertical margin cannot be used with top or bottom margin.');
      }
    }
    return true;
  }());
  return Container(
    margin: EdgeInsets.only(
      top: top ?? vertical ?? all ?? 0,
      bottom: bottom ?? vertical ?? all ?? 0,
      left: left ?? horizontal ?? all ?? 0,
      right: right ?? horizontal ?? all ?? 0,
    ),
    child: this,
  );
}