Custom Padding Widgets using Flutter for Clearly Designed and Useful Layouts for Big Projects

Meet DabhiMeet Dabhi
1 min read

In this blog post, we explore how to create a versatile Custom Padding widget in Flutter, designed to simplify and streamline your UI design process. By providing a reusable padding component that can adapt to various layout needs, you can ensure cleaner code and more efficient layouts. This guide is perfect for both beginner and experienced Flutter developers who seek to maintain organized and manageable code in their projects. Follow along as we build a Custom Padding widget, understand its flexible parameters, and see practical examples of its use in real-world applications. Enhance your Flutter apps with easy-to-use and customizable padding components today!

import 'package:flutter/material.dart';

class CommonWidget {
  static Widget padding({
    Widget? child,
    EdgeInsetsGeometry? padding,
    double? paddingAllSide,
    bool isPaddingAllSide = false,
    double? left,
    double? top,
    double? right,
    double? bottom,
    double? vertical,
    double? horizontal,
  }) {
    // Calculate padding based on provided parameters
    EdgeInsetsGeometry finalPadding = padding ??
        (isPaddingAllSide
            ? EdgeInsets.all(paddingAllSide ?? 0.0)
            : EdgeInsets.only(
                left: left ?? horizontal ?? 0.0,
                top: top ?? vertical ?? 0.0,
                right: right ?? horizontal ?? 0.0,
                bottom: bottom ?? vertical ?? 0.0,
              ));

    return Padding(
      padding: finalPadding,
      child: child,
    );
  }
}
1
Subscribe to my newsletter

Read articles from Meet Dabhi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Meet Dabhi
Meet Dabhi

Welcome to Flutter Hub! I'm Meet Dabhi, a Flutter developer with 3+ years of experience in creating beautiful and functional mobile applications (Android, IOS, Web, MacOS, etc.) My journey with Flutter began in 3+, and since then, I've been dedicated to mastering this powerful framework. I created Flutter Hub to share my knowledge, insights, and the latest trends in the Flutter community. Through this blog, I aim to provide valuable resources for both beginners and seasoned developers, helping them navigate the ever-evolving world of Flutter development.