Flutter › Layout Widgets (Row, Column, Stack, Container)
What is the Container widget, and how does it let you conveniently combine padding, margin, background color, and border decoration all together within just one single genuinely convenient widget?
BeginnerAnswer
Container is a genuinely versatile, commonly used widget that conveniently combines several separate common visual and layout properties together, including padding for adding internal space around its own child, margin for adding external space around itself, a background color or a more genuinely detailed decoration, and explicit width and height constraints, letting you achieve a whole variety of common everyday visual effects using just this one single convenient widget rather than needing to separately nest several genuinely separate individual smaller widgets together to achieve that exact same combined resulting effect.
Container(
padding: EdgeInsets.all(16),
margin: EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.circular(8)),
child: Text('Hello'),
)Real-world example A notification card uses a single Container to conveniently apply padding, a rounded blue background, and appropriate external margin all together at once, achieving a genuinely polished visual result without needing to separately nest several individual smaller widgets together.