Skip to content

Instantly share code, notes, and snippets.

@samuelematias
Created March 12, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelematias/a2ab7476f206982af65f11a964d0555b to your computer and use it in GitHub Desktop.
Save samuelematias/a2ab7476f206982af65f11a964d0555b to your computer and use it in GitHub Desktop.
Examples of Dart extension methods
extension Paddings on Widget {
Widget paddingAll(double padding) => Padding(
padding: EdgeInsets.all(padding),
child: this,
);
}
extension TextStyles on Text {
Text h1() {
if (this is Text) {
final Text t = this;
return Text(
t.data,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 50.0,
fontFamily: merriweather,
),
);
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment