← Flutter tutorial

Flutter

Layout with Row, Column & Container

Row arranges its children left-to-right; Column arranges them top-to-bottom.

Example: three colored squares in a row

Widget build(BuildContext context) {
  return Row(
    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
    children: [
      Container(color: Colors.blue, width: 50, height: 50),
      Container(color: Colors.orange, width: 50, height: 50),
      Container(color: Colors.green, width: 50, height: 50),
    ],
  );
}

Renders three evenly-spaced colored squares (blue, orange, green) in a horizontal row.

Container wraps a single child to add padding, margin, size, or a background color, it's the Flutter equivalent of a styled <div> from CSS. mainAxisAlignment: MainAxisAlignment.spaceEvenly plays a nearly identical role to CSS flexbox's justify-content: space-evenly, if you've read the CSS tutorial's Flexbox lesson, this should feel like a direct parallel, not a new concept.

Example
Widget build(BuildContext context) {
  return Row(
    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
    children: [
      Container(color: Colors.blue, width: 50, height: 50),
      Container(color: Colors.orange, width: 50, height: 50),
      Container(color: Colors.green, width: 50, height: 50),
    ],
  );
}
Output
Renders three evenly-spaced colored squares (blue, orange, green) in a horizontal row.
Ready to go further?

These free tutorials are a preview of what a Code Secure Academy cohort covers, project work and all.

Explore our tracks

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account