Conversation

Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!

Join the discussion and share your insights now!

Comments 0

Sharpen your coding skills—try JavaScript challenges on TOOLX now!

advertisement

Padding widget in Flutter

Padding Widget in Flutter

The padding widget adds space between widgets. It is possible to apply padding to any widget by placing the padding widget as a child. It is a single-child layout widget.


Properties of the padding widget




1. EdgeInsets.all():

Helps to apply white spaces on all sides.

Padding: EdgeInsets.all(10.0)


2. EdgeInsets.fromLTRB():

Provides padding on individual sides. Here, LTRB refers to L-Left, T-Top, R-Right, and B-Bottom.

Padding: EdgeInsets.fromLTRB(10, 5, 10, 5)


3. EdgeInsets.only():

Helps to apply whitespace to a given corner or padding to a specific side of the widget.

Padding: EdgeInsets.only(left: 20, top: 30)


When and How to Use a Padding Widget?

Padding can be used whenever the user wants to add extra space around any widget. Several types of padding are available, and it is possible to choose which type to implement based on the user's requirements.


Video Source Code

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Padding with Border Example'),
        ),
        body: Center(
          child: Container(
            decoration: BoxDecoration(
              border: Border.all(color: Colors.black, width: 3.0)
            ),
            child: Padding(
              // padding: EdgeInsets.only(left: 20.0, top: 20.0),
              // padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
              padding: EdgeInsets.all(10),
              child: Text('Hello, Padding with Border!'),
            ),
          ),
        ),
      ),
    );
  }
}


Flutter Padding Widget - Flutter Complete Tutorial




Flutter Flutter Widgets Padding Widget Padding Widget in Flutter Flutter padding widget Padding Widget with example Padding Widget Properties properties of the padding widget how to use a padding widget

advertisement