Skip to content

Instantly share code, notes, and snippets.

@MelbourneDeveloper
Created June 30, 2023 13:30
Show Gist options
  • Save MelbourneDeveloper/e57efa4714b373a6241d5928d479d24c to your computer and use it in GitHub Desktop.
Save MelbourneDeveloper/e57efa4714b373a6241d5928d479d24c to your computer and use it in GitHub Desktop.
pad Extension
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
body: Center(
child: Row(children: [
Container(
color: Colors.red,
width: 100,
height: 100,
).pad(all: 16),
Container(
color: Colors.orange,
width: 100,
height: 100,
).pad(symmetric: (16, 16)),
Container(
color: Colors.purple,
width: 100,
height: 100,
).pad(ltrb: (16, 16, 16, 16))
]),
),
),
),
);
}
extension WidgetExtensions on Widget {
Padding pad({
double? all,
(double left, double top, double right, double bottom)? ltrb,
(double horizontal, double vertical)? symmetric,
Key? key,
}) =>
Padding(
padding: all != null
//all
? EdgeInsets.all(all)
//LTRB
: ltrb != null
? EdgeInsets.fromLTRB(ltrb.$1, ltrb.$2, ltrb.$3, ltrb.$4)
: symmetric != null
//Symmetric
? EdgeInsets.symmetric(
horizontal: symmetric.$1, vertical: symmetric.$2)
//None
: EdgeInsets.zero,
key: key,
child: this,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment