HomeAbout MeContact Me

Flutter Padding widgets generator with Paddinger

By Emanuele Papa
Published in Development
May 16, 2021
1 min read
Flutter Padding widgets generator with Paddinger

Paddinger is a new package to help you deal with Flutter paddings and here you’ll discover how!

Have you ever been tired of writing Padding and EdgeInsets boilerplate everytime you need to add padding to a widget? I was, so I started looking for something to simplify this task. Furthermore, the necessary code to create declarative UIs can become very long and difficult to read, so, if there is a way to reduce it even by a few lines it’s something always worth to be considered.

I found out I was not the only one who was tired of this Padding boilerplate because, searching for a solution, I found someone else struggling with the same problem. One of the solution I found was Padder, which is available on Github and on pub.dev. It’s a cool set of widgets which can help you dealing with paddings.

Unfortunately, it was not what I was looking for, but having found valid proofs that there was a problem affecting someone else other than me, I decided to build what I needed on my own, and so Paddinger was born.

What is Paddinger

Paddinger is a code generator for Flutter: it builds Padding widgets for you based on the values you have in your design system. An example is worth a thousand words, so here it is. Assuming you have

const double PADDING_NORMAL = 8;

with Paddinger you will obtain a set of widgets like


just by annotating with @paddinger the constants you want the widgets to be generated for, like

const double PADDING_NORMAL = 8;

Then, you can use the generated widgets like every other one. Assuming you want to give a padding of 8 to a Text, instead of writing

  padding: const EdgeInsets.all(PADDING_NORMAL),
  child: Text(

you can just write

  child: Text(

which imho is far easier to remember, to write, to read and IDE code completion will come to rescue!

How to use Paddinger in your project

  • First of all, add Paddinger as a dependency:
  paddinger_annotations: [latestVersionHere]

  paddinger: [latestVersionHere]
  • Create a file where you will add all your PADDING_ constants, the file could be named paddings.dart.
  • Add your favourite material or cupertino import like:
// ignore: unused_import
import 'package:flutter/material.dart';
  • Add the part directive:
part 'paddings.g.dart';

Now run the code generation with flutter pub run build_runner build --delete-conflicting-outputs and your widgets will be generated and ready to be used!

You can have a look at the example in the Github repository or on pub.dev.

Happy Fluttering!


Previous Article
Clear all Android SharedPreferences
Emanuele Papa

Emanuele Papa

Android Developer


Smart Home

Related Posts

How to debug an Annotation Processor in Android Studio
July 05, 2020
1 min

Quick Links

HomeAbout MeContact MeRSS Feed

Social Media