Labs ICT
โญ Pro Login

Layouts & Responsive Design

Building responsive layouts with Flutter

Layouts & Responsive Design

Flutter provides powerful layout widgets that let you create responsive designs that work across different screen sizes. Understanding these layouts is key to building beautiful apps.

Common Layout Widgets


  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚           Layout Widgets                        โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚                                                  โ”‚
  โ”‚  Row        โ†’ Horizontal arrangement            โ”‚
  โ”‚  โ”Œโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”                                 โ”‚
  โ”‚  โ”‚ A โ”‚ B โ”‚ C โ”‚                                 โ”‚
  โ”‚  โ””โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”˜                                 โ”‚
  โ”‚                                                  โ”‚
  โ”‚  Column   โ†’ Vertical arrangement                โ”‚
  โ”‚  โ”Œโ”€โ”€โ”€โ”                                         โ”‚
  โ”‚  โ”‚ A โ”‚                                         โ”‚
  โ”‚  โ”œโ”€โ”€โ”€โ”ค                                         โ”‚
  โ”‚  โ”‚ B โ”‚                                         โ”‚
  โ”‚  โ”œโ”€โ”€โ”€โ”ค                                         โ”‚
  โ”‚  โ”‚ C โ”‚                                         โ”‚
  โ”‚  โ””โ”€โ”€โ”€โ”˜                                         โ”‚
  โ”‚                                                  โ”‚
  โ”‚  Stack    โ†’ Overlapping elements                โ”‚
  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                โ”‚
  โ”‚  โ”‚  Background โ”‚                                โ”‚
  โ”‚  โ”‚   โ”Œโ”€โ”€โ”€โ”    โ”‚                                โ”‚
  โ”‚  โ”‚   โ”‚ B โ”‚ โ† Overlay                           โ”‚
  โ”‚  โ”‚   โ””โ”€โ”€โ”€โ”˜    โ”‚                                โ”‚
  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                โ”‚
  โ”‚                                                  โ”‚
  โ”‚  Wrap    โ†’ Flow with wrapping                   โ”‚
  โ”‚  โ”Œโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”                                 โ”‚
  โ”‚  โ”‚ A โ”‚ B โ”‚ C โ”‚                                 โ”‚
  โ”‚  โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”ค                                 โ”‚
  โ”‚  โ”‚ D โ”‚ E โ”‚ F โ”‚                                 โ”‚
  โ”‚  โ””โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”˜                                 โ”‚
  โ”‚                                                  โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Responsive Layout Example


import 'package:flutter/material.dart';

class ResponsiveLayout extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: LayoutBuilder(
        builder: (context, constraints) {
          if (constraints.maxWidth > 600) {
            return _buildWideLayout();
          } else {
            return _buildNarrowLayout();
          }
        },
      ),
    );
  }

  Widget _buildWideLayout() {
    return Row(
      children: [
        Expanded(
          flex: 1,
          child: Container(color: Colors.blue, child: Center(child: Text('Side Menu'))),
        ),
        Expanded(
          flex: 3,
          child: Container(color: Colors.grey[200], child: Center(child: Text('Main Content'))),
        ),
      ],
    );
  }

  Widget _buildNarrowLayout() {
    return Column(
      children: [
        Expanded(child: Container(color: Colors.blue, child: Center(child: Text('Header')))),
        Expanded(flex: 3, child: Container(color: Colors.grey[200], child: Center(child: Text('Content')))),
      ],
    );
  }
}

Key Tips for Responsive Design

  • Use LayoutBuilder: Get parent constraints to make decisions
  • Use MediaQuery: Get device screen size and orientation
  • Avoid hardcoded sizes: Use percentages and flexible widgets
  • Test on multiple devices: Phones, tablets, and desktop

๐Ÿงช Quick Quiz

Which Flutter layout allows children to be positioned freely?