Responsive Layout Widget

Estimated reading: 4 minutes 141 views

FlutKit provides a dedicated widget, AdaptiveWrap, to help developers build responsive and adaptive page layouts without manually checking screen widths or writing multiple LayoutBuilder conditions. This widget intelligently switches the number of columns and adapts the width ratios based on breakpoints you define.

Common Use Cases

Use AdaptiveWrap when you want to:

  • Create multi-column layouts that adapt to screen width
  • Control column count per breakpoint
  • Maintain consistent spacing between widgets
  • Avoid manual responsive calculations

Common use cases include dashboards, forms, settings pages, and content panels.

Accordion Constructor

Dart
AdaptiveWrap({
  Key? key,
  required List<Widget> children,
  double spacing = kDefaultPadding,
  double runSpacing = kDefaultPadding,
  int? maxColumns,
  int? minColumns,
  List<double>? columnRatios,
  Map<double, int>? breakpoints,
  WrapAlignment alignment = WrapAlignment.start,
  WrapCrossAlignment crossAlignment = WrapCrossAlignment.start,
  double? itemHeight,
  void Function(int)? onLayoutChanged,
  bool useScreenWidth = false,
})

Parameter Explanation

AdaptiveWrap is a responsive layout widget designed to simplify adaptive, multi-column content layouts across different screen sizes. It dynamically adjusts the number of columns based on available width or defined breakpoints.

children (required)

Dart
required List<Widget> children,

A list of widgets that will be arranged into adaptive columns.

Each widget represents a layout item. The number of visible columns depends on breakpoints, constraints, or column settings.

spacing

Dart
double spacing = kDefaultPadding,

Horizontal spacing between columns.

Use this to control the gap between items in the same row.

runSpacing

Dart
double runSpacing = kDefaultPadding,

Vertical spacing between rows.

This spacing is applied when items wrap into the next line.

maxColumns

Dart
int? maxColumns,

The maximum number of columns allowed.

If set, the layout will never exceed this number of columns, even on very large screens.

minColumns

Dart
int? minColumns,

The minimum number of columns allowed.

Ensures a consistent layout by preventing the layout from collapsing below a certain number of columns.

columnRatios

Dart
List<double>? columnRatios,

Defines the width ratio of each column.

Example:

Dart
columnRatios: [0.7, 0.3],
  • Column A uses 70% of available width
  • Column B uses 30% of available width

The number of ratios should match the active column count.

breakpoints

Dart
Map<double, int>? breakpoints,

Defines how many columns should be displayed at specific width thresholds.

Example:

Dart
breakpoints: {
  576: 1,
  768: 2,
  1024: 3,
},

Behavior:

  • Width < 576 → 1 column
  • 576 ≤ width < 768 → 2 columns
  • 768 ≤ width < 1024 → 3 columns
  • If no additional breakpoints are defined, the number of columns for larger screen widths remains 3, following the last specified breakpoint.

useScreenWidth

Dart
bool useScreenWidth = false,

Determines how layout width is calculated.

  • false (default): uses parent constraints
  • true: uses full screen width (MediaQuery)

alignment

Dart
WrapAlignment alignment = WrapAlignment.start,

Controls horizontal alignment of items within each row.

Values:

  • WrapAlignment.start
  • WrapAlignment.center
  • WrapAlignment.spaceBetween
  • WrapAlignment.spaceAround

crossAlignment

Dart
WrapCrossAlignment crossAlignment = WrapCrossAlignment.start,

Controls vertical alignment of items within a row.

Useful when items have different heights.

onLayoutChanged

Dart
void Function(int)? onLayoutChanged,

Callback triggered when the number of active columns changes.

The callback returns:

  • int: the current number of columns

Use cases:

  • Adjust UI logic based on layout
  • Trigger animations or data loading per layout change

Summary Table

ParameterPurpose
childrenWidgets to be laid out
spacingHorizontal spacing
runSpacingVertical spacing
maxColumnsMaximum column count
minColumnsMinimum column count
columnRatiosColumn width proportions
breakpointsResponsive column rules
alignmentHorizontal alignment
crossAlignmentVertical alignment
itemHeightFixed item height
onLayoutChangedLayout change callback
useScreenWidthUse full screen width

Basic Example

Dart
AdaptiveWrap(
  breakpoints: {
    576: 1,
    768: 2,
  },
  columnRatios: const [
    0.7,
    0.3,
  ],
  spacing: 16,
  runSpacing: 16,
  children: [
    _demoCard('Column A', kSecondaryColor),
    _demoCard('Column B', kInfoColor),
  ],
),

Find several use case examples in the demo, please navigate to:

Dart
Base UILayout

Best Practices

  • Define breakpoints that match your design system
  • Use consistent columnRatios across similar screens
  • Avoid deeply nested layouts inside AdaptiveWrap
  • Pair with FlutKit cards and panels for consistent UI

Practical Use Case Example

A common dashboard layout:

  • Desktop: Content + Sidebar (2 columns)
  • Tablet: Stacked but still 2 columns
  • Mobile: Single-column stacked layout

AdaptiveWrap handles all of this with a single widget configuration.

Summary

AdaptiveWrap allows you to build clean, scalable, and responsive layouts with minimal code. By defining breakpoints and column ratios, you can focus on content rather than layout logic.

This makes it an ideal solution for FlutKit dashboards and adaptive content pages.

Share this Doc

Responsive Layout Widget

Or copy link

CONTENTS