Expanded Widget in Flutter

Expanded is a layout widget that expands a child of a Row, Column, or Flex to fill available space. It lets you build flexible, adaptive UIs where widgets automatically take up proportionate space.

Source Code​

				
					Row(
  children: [
    Expanded(
      child: Container(
        color: Colors.teal,
        height: 100,
        child: Center(child: Text('Left')),
      ),
    ),
    Container(
      width: 100,
      height: 100,
      color: Colors.orange,
      child: Center(child: Text('Right')),
    ),
  ],
)


//With flex Property (Proportional Space)

Row(
  children: [
    Expanded(
      flex: 2,
      child: Container(color: Colors.blue, height: 100),
    ),
    Expanded(
      flex: 1,
      child: Container(color: Colors.green, height: 100),
    ),
  ],
)

				
			

Ai Code Analizer

🧩 Typical Use Cases

  • Make widgets fill remaining space.

  • Create proportional layouts inside Row or Column.

  • Prevent overflow by allowing widgets to resize.


🎨 Important Notes

PropertyDescription
flexInteger value that determines proportion
childThe widget to expand
Must be inside Row, Column, or FlexWon’t work in other containers