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

# AspectRatio

> Documentation for AspectRatio

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

export const aspectRatioPreviewJson = {
  "type": "aspectRatio",
  "aspectRatio": 1.33,
  "child": {
    "type": "container",
    "color": "#FF5733",
    "width": 100,
    "height": 100
  }
};
export const aspectRatioPreviewSrc = `${PLAYGROUND_BASE_URL}/embed`;

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

## Properties

| Property      | Type         | Description                                                                                      |
| ------------- | ------------ | ------------------------------------------------------------------------------------------------ |
| `aspectRatio` | `double`     | The desired width-to-height ratio for the child widget. Defaults to `1` (a square aspect ratio). |
| `child`       | `StacWidget` | The child widget that should adhere to the specified aspect ratio, represented as a JSON object. |

***

## Example

<Tabs sync={false}>
  <Tab title="Dart">
    ```dart theme={null}
    StacAspectRatio(
      aspectRatio: 1.33,
      child: StacContainer(
        color: '#FF5733',
        width: 100,
        height: 100,
      ),
    )
    ```
  </Tab>

  <Tab title="JSON">
    ```json theme={null}
    {
      "type": "aspectRatio",
      "aspectRatio": 1.33,
      "child": {
        "type": "container",
        "color": "#FF5733",
        "width": 100,
        "height": 100
      }
    }
    ```
  </Tab>

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

      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>
