> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stac.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Flexible

> Documentation for Flexible

export const PLAYGROUND_BASE_URL = "https://playground.stac.dev/";

export const flexiblePreviewJson = {
  "type": "flexible",
  "flex": 2,
  "fit": "tight",
  "child": {
    "type": "text",
    "data": "Hello, World!"
  }
};
export const flexiblePreviewSrc = `${PLAYGROUND_BASE_URL}/embed`;

The Stac Flexible allows you to build a Flutter flexible widget using JSON.
To know more about the flexible widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/Flexible-class.html).

## Properties

| Property | Type          | Description                                                                              |
| -------- | ------------- | ---------------------------------------------------------------------------------------- |
| child    | `StacWidget`  | The widget to display inside the flexible widget.                                        |
| flex     | `int`         | The flex factor to use for the flexible widget. Defaults to `1`.                         |
| fit      | `StacFlexFit` | How the child should be inscribed into the available space. Defaults to `FlexFit.loose`. |

## Example

<Tabs sync={false}>
  <Tab title="Dart">
    ```dart theme={null}
    StacFlexible(
      flex: 2,
      fit: StacFlexFit.tight,
      child: StacText(data: 'Hello, World!'),
    )
    ```
  </Tab>

  <Tab title="JSON">
    ```json theme={null}
    {
      "type": "flexible",
      "flex": 2,
      "fit": "tight",
      "child": {
        "type": "text",
        "data": "Hello, World!"
      }
    }
    ```
  </Tab>

  <Tab title="Preview">
    <Frame>
      <iframe
        id="stac"
        src={flexiblePreviewSrc}
        title="Stac Playground"
        className="w-full rounded-xl border-0"
        style={{ height: "640px" }}
        loading="lazy"
        onLoad={(event) => {
      const iframe = event.currentTarget;
      const targetOrigin = PLAYGROUND_BASE_URL;
      const message = {
        type: "stac-preview-json",
        payload: flexiblePreviewJson
      };

      let attempts = 0;
      const maxAttempts = 12;
      const interval = setInterval(() => {
        iframe.contentWindow?.postMessage(message, targetOrigin);
        attempts += 1;

        if (attempts >= maxAttempts) {
          clearInterval(interval);
        }
      }, 250);
    }}
      />
    </Frame>
  </Tab>
</Tabs>
