# Wrap

The **Wrap** widget is a powerful layout component that arranges its children in a horizontal or vertical sequence, automatically "wrapping" them to the next line when there isn't enough space. This is incredibly useful for creating responsive layouts with a variable number of items, such as a list of tags, a photo gallery, or a set of filter chips.

{% embed url="<https://www.youtube.com/watch?v=haYNAaamK18>" %}

Watch this on Youtube: <https://www.youtube.com/watch?v=haYNAaamK18>

### Core Concepts

#### 1. Axis and Wrapping

Unlike `Row` or `Column`, which force children into a single line, `Wrap` is flexible. It attempts to lay out children along its main axis (`Direction`) and, if it runs out of room, it simply moves to the next line on the cross axis.

* **Direction**: The primary axis along which children are placed. This can be `Horizontal` (like a `Row`) or `Vertical` (like a `Column`).
* **Wrapping**: When children overflow the available space on the main axis, they wrap onto a new "run" on the cross axis.

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-b6016391849470dfa058f42b92ad4db3bb870b21%2Fwrap_axis.jpg?alt=media" alt="A diagram showing the main and cross axis of a Wrap widget."><figcaption><p>Example of a Wrap widget where items wrap to a new line.</p></figcaption></figure>

#### 2. Dynamic Children

Similar to `Row` and `Column`, the `Wrap` widget is perfect for displaying dynamic data. By connecting it to a `Data Source`, you can generate a list of child widgets from a `JsonArray`. This makes it ideal for rendering lists of tags, user-selected choices, or any collection of items where the count is not fixed.

***

### Properties

#### Layout & Spacing

<table><thead><tr><th width="176.25390625">Property</th><th>Description</th></tr></thead><tbody><tr><td><code>Direction</code></td><td>Determines the primary axis for laying out children. <code>Horizontal</code> arranges them in rows, while <code>Vertical</code> arranges them in columns.</td></tr><tr><td><code>Alignment</code></td><td>Defines how children are positioned along the <strong>main axis</strong> (e.g., <code>Start</code>, <code>Center</code>, <code>End</code>, <code>Space Between</code>). This is similar to <code>Main Axis Alignment</code> in a Row/Column.</td></tr><tr><td><code>Run Alignment</code></td><td>Defines how the "runs" (the lines of wrapped children) are distributed along the <strong>cross axis</strong>. For example, if you have a <code>Horizontal</code> wrap with two lines of children, <code>Run Alignment</code> controls the vertical spacing between those lines.</td></tr><tr><td><code>Cross Axis Alignment</code></td><td>Defines how children within the same run are aligned relative to each other along the <strong>cross axis</strong>. For example, in a <code>Horizontal</code> wrap, this controls whether taller and shorter children align to the top, center, or bottom of their line.</td></tr><tr><td><code>Spacing</code></td><td>The amount of empty space to place between each child along the <strong>main axis</strong>.</td></tr><tr><td><code>Run Spacing</code></td><td>The amount of empty space to place between each run along the <strong>cross axis</strong>. For a <code>Horizontal</code> wrap, this is the vertical gap between lines.</td></tr></tbody></table>

### Alignment in horizontal and vertical

The alignment property is used to align the children in the main axis.

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-dd29a3c20bb7af8394e24bf0866bd5610603b5ae%2Fwrap_alignment_horizontal.jpg?alt=media" alt="An image showing horizontal alignment in a Wrap widget."><figcaption><p>The <code>Alignment</code> property controlling the horizontal distribution of children in a <code>Horizontal</code> wrap.</p></figcaption></figure>

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-9b873bdfb283f2a97e92032b289500e174885126%2Fwrap_alignment_vertical.jpg?alt=media" alt="An image showing vertical alignment in a Wrap widget."><figcaption><p>The <code>Alignment</code> property controlling the vertical distribution of children in a <code>Vertical</code> wrap.</p></figcaption></figure>

### RunAlignment in horizontal and vertical

The runAlignment property is used to align the runs in the cross axis.

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-b049c729c12d3bed86466aa0d119180e9b56c7a9%2Fwrap_run_alignment_horizontal.jpg?alt=media" alt="An image showing horizontal run alignment in a Wrap widget."><figcaption><p>The <code>RunAlignment</code> property controlling the vertical distribution of runs in a <code>Horizontal</code> wrap.</p></figcaption></figure>

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-a66d23cb4dd9071a86156683b3fe409ae8cc7fc6%2Fwrap_run_alignment_vertical.jpg?alt=media" alt="An image showing vertical run alignment in a Wrap widget."><figcaption><p>The <code>RunAlignment</code> property controlling the horizontal distribution of runs in a <code>Vertical</code> wrap.</p></figcaption></figure>

### Spacing and RunSpacing

The spacing and runSpacing properties are used to add space between the children and runs respectively.

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-09d7a5e32f7a4db2a11abbf0bdbb9bb606a6c41b%2Fwrap_spacing.jpg?alt=media" alt="An image showing spacing between children in a Wrap widget."><figcaption><p>The <code>Spacing</code> property adds space between children along the run axis</p></figcaption></figure>

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-2af75bc2e503eb89c14037607306d36edc31d14b%2Fwrap_run_spacing.jpg?alt=media" alt="An image showing spacing between runs in a Wrap widget."><figcaption><p>The <code>RunSpacing</code> property adds space between runs.</p></figcaption></figure>

### CrossAxisAlignment in horizontal and vertical

CrossAxisAlignment is used to align the children relative to each other in the cross axis.

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-4f6de23cf667138ef523603139690850913c9ff4%2Fwrap_cross_axis_alignment_horizontal.jpg?alt=media" alt="An image showing CrossAxisAlignment for children in a Horizontal wrap."><figcaption><p>The <code>CrossAxisAlignment</code> property controlling the vertical alignment of children within a run in a <code>Horizontal</code> wrap.</p></figcaption></figure>

<figure><img src="https://3626461507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhApDTL7kHrXte2TTtjs%2Fuploads%2Fgit-blob-e03758fdf315bd669c148c1f68bbff0f83e431c8%2Fwrap_cross_axis_alignment_vertical.jpg?alt=media" alt="An image showing CrossAxisAlignment for children in a Vertical wrap."><figcaption><p>The <code>CrossAxisAlignment</code> property controlling the horizontal alignment of children within a run in a <code>Vertical</code> wrap.</p></figcaption></figure>

***

### Children: Static vs. Dynamic

You can populate a `Wrap` widget with child widgets in two ways:

#### 1. Static Children

Add a fixed number of child widgets directly in the builder. Each child you add will appear in the widget tree, and its properties can be configured individually. This is ideal for layouts where the number of items is known and doesn't change.

#### 2. Dynamic Children

To generate children from a list of data, you can use the **`Data Source`** property. This turns the `Wrap` widget into a powerful list builder.

1. Enable the `Data Source` toggle in the properties panel.
2. Provide data by either entering a fixed `JsonArray` in the JSON editor or binding it to an expression that returns a `JsonArray` (e.g., from an API call or App State).
3. Add a **single child widget** to the `Wrap`. This widget acts as a template that will be repeated for each item in the data source.
4. Inside this template child, use the `currentItem` variable to access the data for each item.
   * If your data is a list of objects (e.g., `[{"name": "Apple"}, {"name": "Banana"}]`), access properties with dot notation: `${currentItem.name}`.
   * If your data is a list of simple values (e.g., `["Apple", "Banana"]`), `currentItem` refers to the value itself: `${currentItem}`.

This is perfect for building a dynamic list of filter chips, product tags, or any other repeating UI element that needs to wrap gracefully.

***

## Default Properties

The Wrap widget supports all [default-properties](https://docs.digia.tech/ui-building-blocks/widgets/default-properties "mention").

### Use Cases

The **Wrap** widget is used when items need to **automatically move to the next line** instead of overflowing.

Use **Wrap** when you want to:

* **Display chips or tags**
  * Filters, categories, interests, labels that may be many in number
  * They should wrap onto the next line when they don’t fit in one row
* **Responsive pill / button groups**
  * Small buttons, shortcuts, or options that should flow naturally on small and large screens
* **Inline icon/text groups that wrap**
  * Badges, info pills, or small cards that shouldn’t require horizontal scrolling
