Container in Flutter

A Container is a versatile widget used to wrap, style, position, and size other widgets. It’s commonly used for adding padding, background colors, borders, margins, alignment, and more.

Source Code​

				
					Container(
  padding: EdgeInsets.all(16),
  margin: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
  alignment: Alignment.center,
  decoration: BoxDecoration(
    color: Colors.teal,
    borderRadius: BorderRadius.circular(12),
    boxShadow: [
      BoxShadow(
        color: Colors.black26,
        blurRadius: 6,
        offset: Offset(0, 3),
      ),
    ],
  ),
  height: 100,
  width: double.infinity,
  child: Text(
    'Hello Container',
    style: TextStyle(color: Colors.white, fontSize: 18),
  ),
)

				
			

Ai Code Analizer

🎨 3. Important Properties Used

PropertyDescription
paddingSpace inside the container, around its child.
marginSpace outside the container, separating it from other widgets.
alignmentAligns the child within the container.
decorationAdds background color, border, radius, shadow, etc.
height/widthSets fixed size. Use double.infinity to fill available space.
childThe widget inside the container (usually Text, Row, Column, etc.).

🎯 Bonus: BoxDecoration Customization

You can use BoxDecoration to style your container further:

  • color: Set background color.

  • border: Add custom borders.

  • borderRadius: Round the corners.

  • boxShadow: Add shadows for depth.

  • gradient: Use linear or radial gradients.