withPadding method

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

Wraps this widget in a Padding with the given values. If all is provided, it overrides other parameters. Example:

myWidget.withPadding(all: 16);
myWidget.withPadding(horizontal: 8, vertical: 16);
myWidget.withPadding(top: 10, bottom: 20);

Implementation

Widget withPadding({
  double? all,
  double? horizontal,
  double? vertical,
  double? top,
  double? bottom,
  double? left,
  double? right,
}) {
  if (all != null) {
    return Padding(padding: EdgeInsets.all(all), child: this);
  }

  return Padding(
    padding: EdgeInsets.only(
      top: vertical ?? top ?? 0,
      bottom: vertical ?? bottom ?? 0,
      left: horizontal ?? left ?? 0,
      right: horizontal ?? right ?? 0,
    ),
    child: this,
  );
}