Flutter Spacer Widget

The Spacer Widget in Flutter is used to create flexible or empty space between widgets. It takes up available space and is useful in situations where you need to adjust the amount of space between widgets dynamically. 

This article provides a code sample and properties of the Spacer widget in Flutter.

Code Sample: Here is an example of using the Spacer widget in a Row widget:


Row(
  children: [
    Expanded(
      child: Container(
        color: Colors.red,
        height: 50,
      ),
    ),
    const Spacer(), // Creates empty space between widgets
    Expanded(
      child: Container(
        color: Colors.blue,
        height: 50,
      ),
    ),
  ],
);

..

Properties:

The Spacer widget has the following properties:

flex: an integer value that specifies the flex factor for the widget. By default, the flex factor is 1.

Note: 

The flex factor determines how much space a widget should occupy in a flexible space. The higher the flex factor, the more space the widget will occupy. If multiple widgets have the same flex factor, the space will be divided equally among them. If one widget has a higher flex factor than the others, it will occupy more space.

Comments