> ## 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.

# FittedBox

> Documentation for FittedBox

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

export const fittedBoxPreviewJson = {
  "type": "fittedBox",
  "fit": "contain",
  "alignment": "center",
  "child": {
    "type": "text",
    "data": "Hello, World!",
    "style": {
      "fontSize": 20,
      "color": "#000000"
    }
  }
};
export const fittedBoxPreviewSrc = `${PLAYGROUND_BASE_URL}/embed`;

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

***

## Properties

| Property       | Type                       | Description                                                                          |
| -------------- | -------------------------- | ------------------------------------------------------------------------------------ |
| `fit`          | `StacBoxFit`               | Defines how the child should be fitted within the box. Defaults to `BoxFit.contain`. |
| `alignment`    | `StacAlignmentDirectional` | Aligns the child within the box. Defaults to `StacAlignmentDirectional.center`.      |
| `clipBehavior` | `StacClip`                 | Specifies whether and how the content should be clipped. Defaults to `Clip.none`.    |
| `child`        | `StacWidget`               | The child widget, represented as a JSON object, to be positioned and scaled.         |

***

## Example

<Tabs sync={false}>
  <Tab title="Dart">
    ```dart theme={null}
    StacFittedBox(
      fit: StacBoxFit.contain,
      alignment: StacAlignment.center,
      child: StacText(
        data: 'Hello, World!',
        style: StacTextStyle(
          fontSize: 20,
          color: StacColors.black,
        ),
      ),
    )
    ```
  </Tab>

  <Tab title="JSON">
    ```json theme={null}
    {
      "type": "fittedBox",
      "fit": "contain",
      "alignment": "center",
      "child": {
        "type": "text",
        "data": "Hello, World!",
        "style": {
          "fontSize": 20,
          "color": "#000000"
        }
      }
    }
    ```
  </Tab>

  <Tab title="Preview">
    <Frame>
      <iframe
        id="stac"
        src={fittedBoxPreviewSrc}
        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: fittedBoxPreviewJson
      };

      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>
