15 min. • Jun 6, 2023
Flutter is known for its seamless UI/UX features and robust design elements. It allowed us to deliver a unique customer experience in the “CA24 Mobile” banking app. This article shares some of the learnings and pain points behind implementing it in this large project.
9 min. • Jun 1, 2023
Building a new digital product, such as a web or mobile application, is complex. You need to map user stories - create a simple description of features - then apply them to the developers' scope of work and the app’s design. Discover how a design system can unleash efficiency, consistency, and scalability in your digital product.
The Container widget in Flutter is a convenience widget that combines layout, painting, and positioning into a single API. It can apply padding, margin, alignment, size constraints, background color, and decoration around one child.
Container is not a low-level widget. Internally, it builds other widgets like Padding, Align, DecoratedBox, and ConstrainedBox depending on which properties you use.
Container is often overused as a default wrapper. Understanding how it works helps you:
Misusing containers can lead to layout issues, performance overhead, and confusing behavior.
Container conditionally composes its internal widget tree.
If you provide:
padding → Paddingalignment → Aligndecoration or color → DecoratedBoxwidth / height → ConstrainedBoxIf Container has no child and no visual or layout properties, it should not be used.
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(12),
),
child: const Text('Hello'),
);Use Container when you need multiple responsibilities at once, for example:
padding + background colormargin + alignmentIt works well for simple UI blocks like cards or badges.
Avoid Container when only one concern is needed:
PaddingSizedBoxAlignColoredBoxDecoratedBoxThese widgets are clearer and often cheaper to rebuild.
Several pitfalls appear frequently:
borderRadius clips the child: BoxDecoration does not clip child content. Images can overflow rounded corners. Use clipBehavior: Clip.hardEdge if clipping is required.Container to be clickable: Container without a color does not participate in hit testing. Use color: Colors.transparent for clickable transparent areas.color and decoration: This causes a runtime assertion error.Containers inside other Containers without reason.To use Container effectively:
Container cannot be const.Container in large lists just to add padding.