Skip to content

WSpacer

View raw .md

The WSpacer is a lightweight widget designed specifically for adding consistent gaps between elements. Unlike WDiv, which supports a full range of decorations and layout properties, WSpacer renders as a simple SizedBox, making it highly efficient for layouts where you only need spacing.

On this page
Preview widgets/w_spacer_basic The live demo is not available for this example. w_spacer_basic.dart View source
dart
WDiv(
  className: 'flex flex-col',
  children: [
    WText('Label', className: 'font-bold'),
    WSpacer(className: 'h-2'), // 8px vertical gap
    WInput(placeholder: 'Enter text...'),
  ],
)

Basic Usage#

The WSpacer widget extracts width and height values from your utility classes and applies them to a SizedBox. It supports the standard Wind spacing scale (based on a 4px unit by default).

Vertical Spacing#

Use the h-{n} classes to add vertical gaps in columns:

dart
WSpacer(className: 'h-4') // 16px height

Horizontal Spacing#

Use the w-{n} classes to add horizontal gaps in rows:

dart
WSpacer(className: 'w-2') // 8px width

Constructor#

dart
const WSpacer({
  Key? key,
  String? className,
})

Props#

Prop Type Default Description
className String? null Wind utility classes for sizing (h-, w-).

Responsive Spacing#

You can adjust spacing based on screen size using responsive prefixes. This is particularly useful for increasing margins on tablet or desktop layouts.

Preview widgets/w_spacer_responsive The live demo is not available for this example. w_spacer_responsive.dart View source
dart
WSpacer(className: 'h-4 md:h-8')

Why WSpacer?#

While you could use WDiv with padding or margin, WSpacer is preferred for explicit gaps for several reasons:

  1. Performance: It bypasses complex composition and renders as a single SizedBox.
  2. Semantics: It clearly communicates "this widget exists only for spacing" to other developers.
  3. Convenience: It replaces the verbose SizedBox(height: 16) with the more maintainable WSpacer(className: 'h-4').

All Supported Classes#

Category Classes Description
Sizing h-{n}, w-{n} Standard scale (h-1, h-2, etc.)
Arbitrary h-[15px], w-[2px] Custom pixel values
Responsive md:h-*, lg:w-* Breakpoint-specific spacing

Customizing Theme#

The pixel values for h-{n} and w-{n} are derived from the baseSpacingUnit in your theme.

dart
WindThemeData(
  baseSpacingUnit: 4.0, // Default: h-1 = 4px
)
esc

Search index did not load.

No match for "".

Try a class like rounded-lg or a widget like WButton.