-
-
Notifications
You must be signed in to change notification settings - Fork 109
feat: add StacIntrinsicHeight and StacIntrinsicWidth widgets #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
divyanshub024
merged 1 commit into
StacDev:main
from
akoflacko:feat/intrinsic-height-width
Sep 11, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| --- | ||
| title: "IntrinsicHeight" | ||
| description: "Documentation for IntrinsicHeight" | ||
| --- | ||
|
|
||
| import { PLAYGROUND_BASE_URL } from "/snippets/playground_base.mdx"; | ||
|
|
||
| export const intrinsicHeightPreviewJson = { | ||
| "type": "intrinsicHeight", | ||
| "child": { | ||
| "type": "row", | ||
| "crossAxisAlignment": "stretch", | ||
| "children": [ | ||
| { | ||
| "type": "container", | ||
| "width": 60, | ||
| "color": "#FF5733", | ||
| "child": { | ||
| "type": "text", | ||
| "data": "Short" | ||
| } | ||
| }, | ||
| { | ||
| "type": "container", | ||
| "width": 60, | ||
| "color": "#33A1FF", | ||
| "child": { | ||
| "type": "text", | ||
| "data": "A much longer piece of text" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| }; | ||
| export const intrinsicHeightPreviewSrc = `${PLAYGROUND_BASE_URL}/embed`; | ||
|
|
||
| The Stac IntrinsicHeight allows you to build a Flutter intrinsic height widget using JSON. | ||
| To know more about the intrinsic height widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/IntrinsicHeight-class.html). | ||
|
|
||
| `IntrinsicHeight` sizes its child to the child's maximum intrinsic height. It is most useful | ||
| inside a `row` that uses `crossAxisAlignment: stretch`, when the row itself sits somewhere | ||
| with an unbounded height — for example inside a horizontally scrolling | ||
| `singleChildScrollView` that is itself inside a vertically scrolling list. In that situation | ||
| `stretch` has no finite height to stretch its children into and layout fails; wrapping the | ||
| `row` in `intrinsicHeight` computes a real height first, so every child of the row ends up | ||
| the same height as the tallest one. | ||
|
|
||
| <Warning> | ||
| `intrinsicHeight` is relatively expensive because it performs a speculative extra layout | ||
| pass before the final layout. Prefer giving the child a fixed height where you can, and | ||
| reach for `intrinsicHeight` only when the height genuinely needs to be computed from the | ||
| content. | ||
| </Warning> | ||
|
|
||
| ## Properties | ||
|
|
||
| | Property | Type | Description | | ||
| |----------|--------------|----------------------------------------------------------| | ||
| | child | `StacWidget` | The widget to size to its own maximum intrinsic height. | | ||
|
|
||
| ## Example | ||
|
|
||
| <Tabs sync={false}> | ||
| <Tab title="Dart"> | ||
|
|
||
| ```dart | ||
| StacIntrinsicHeight( | ||
| child: StacRow( | ||
| crossAxisAlignment: StacCrossAxisAlignment.stretch, | ||
| children: [ | ||
| StacContainer( | ||
| width: 60, | ||
| color: StacColors.deepOrange, | ||
| child: StacText(data: 'Short'), | ||
| ), | ||
| StacContainer( | ||
| width: 60, | ||
| color: StacColors.blue, | ||
| child: StacText(data: 'A much longer piece of text'), | ||
| ), | ||
| ], | ||
| ), | ||
| ) | ||
| ``` | ||
|
|
||
| </Tab> | ||
| <Tab title="JSON"> | ||
|
|
||
| ```json | ||
| { | ||
| "type": "intrinsicHeight", | ||
| "child": { | ||
| "type": "row", | ||
| "crossAxisAlignment": "stretch", | ||
| "children": [ | ||
| { | ||
| "type": "container", | ||
| "width": 60, | ||
| "color": "#FF5733", | ||
| "child": { | ||
| "type": "text", | ||
| "data": "Short" | ||
| } | ||
| }, | ||
| { | ||
| "type": "container", | ||
| "width": 60, | ||
| "color": "#33A1FF", | ||
| "child": { | ||
| "type": "text", | ||
| "data": "A much longer piece of text" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </Tab> | ||
| <Tab title="Preview"> | ||
| <Frame> | ||
| <iframe | ||
| id="stac" | ||
| src={intrinsicHeightPreviewSrc} | ||
| 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: intrinsicHeightPreviewJson | ||
| }; | ||
|
|
||
| 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> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| --- | ||
| title: "IntrinsicWidth" | ||
| description: "Documentation for IntrinsicWidth" | ||
| --- | ||
|
|
||
| import { PLAYGROUND_BASE_URL } from "/snippets/playground_base.mdx"; | ||
|
|
||
| export const intrinsicWidthPreviewJson = { | ||
| "type": "intrinsicWidth", | ||
| "child": { | ||
| "type": "column", | ||
| "crossAxisAlignment": "stretch", | ||
| "children": [ | ||
| { | ||
| "type": "container", | ||
| "height": 40, | ||
| "color": "#FF5733", | ||
| "child": { | ||
| "type": "text", | ||
| "data": "Short" | ||
| } | ||
| }, | ||
| { | ||
| "type": "container", | ||
| "height": 40, | ||
| "color": "#33A1FF", | ||
| "child": { | ||
| "type": "text", | ||
| "data": "A much longer piece of text" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| }; | ||
| export const intrinsicWidthPreviewSrc = `${PLAYGROUND_BASE_URL}/embed`; | ||
|
|
||
| The Stac IntrinsicWidth allows you to build a Flutter intrinsic width widget using JSON. | ||
| To know more about the intrinsic width widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/IntrinsicWidth-class.html). | ||
|
|
||
| `IntrinsicWidth` sizes its child to the child's maximum intrinsic width. It is the | ||
| horizontal counterpart of [IntrinsicHeight](/widgets/intrinsic_height) and solves the same | ||
| problem along the other axis — for example a `column` using `crossAxisAlignment: stretch` | ||
| that sits somewhere with an unbounded width. | ||
|
|
||
| <Warning> | ||
| `intrinsicWidth` is relatively expensive because it performs a speculative extra layout | ||
| pass before the final layout. Prefer giving the child a fixed width where you can, and | ||
| reach for `intrinsicWidth` only when the width genuinely needs to be computed from the | ||
| content. | ||
| </Warning> | ||
|
|
||
| ## Properties | ||
|
|
||
| | Property | Type | Description | | ||
| |------------|--------------|-----------------------------------------------------------------------| | ||
| | stepWidth | `double` | If set, forces the child's width to be a multiple of this value. | | ||
| | stepHeight | `double` | If set, forces the child's height to be a multiple of this value. | | ||
| | child | `StacWidget` | The widget to size to its own maximum intrinsic width. | | ||
|
|
||
| ## Example | ||
|
|
||
| <Tabs sync={false}> | ||
| <Tab title="Dart"> | ||
|
|
||
| ```dart | ||
| StacIntrinsicWidth( | ||
| child: StacColumn( | ||
| crossAxisAlignment: StacCrossAxisAlignment.stretch, | ||
| children: [ | ||
| StacContainer( | ||
| height: 40, | ||
| color: StacColors.deepOrange, | ||
| child: StacText(data: 'Short'), | ||
| ), | ||
| StacContainer( | ||
| height: 40, | ||
| color: StacColors.blue, | ||
| child: StacText(data: 'A much longer piece of text'), | ||
| ), | ||
| ], | ||
| ), | ||
| ) | ||
| ``` | ||
|
|
||
| </Tab> | ||
| <Tab title="JSON"> | ||
|
|
||
| ```json | ||
| { | ||
| "type": "intrinsicWidth", | ||
| "child": { | ||
| "type": "column", | ||
| "crossAxisAlignment": "stretch", | ||
| "children": [ | ||
| { | ||
| "type": "container", | ||
| "height": 40, | ||
| "color": "#FF5733", | ||
| "child": { | ||
| "type": "text", | ||
| "data": "Short" | ||
| } | ||
| }, | ||
| { | ||
| "type": "container", | ||
| "height": 40, | ||
| "color": "#33A1FF", | ||
| "child": { | ||
| "type": "text", | ||
| "data": "A much longer piece of text" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </Tab> | ||
| <Tab title="Preview"> | ||
| <Frame> | ||
| <iframe | ||
| id="stac" | ||
| src={intrinsicWidthPreviewSrc} | ||
| 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: intrinsicWidthPreviewJson | ||
| }; | ||
|
|
||
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ages/stac/lib/src/parsers/widgets/stac_intrinsic_height/stac_intrinsic_height_parser.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:stac/src/parsers/core/stac_widget_parser.dart'; | ||
| import 'package:stac_framework/stac_framework.dart'; | ||
| import 'package:stac_core/widgets/intrinsic_height/stac_intrinsic_height.dart'; | ||
|
|
||
| class StacIntrinsicHeightParser extends StacParser<StacIntrinsicHeight> { | ||
| const StacIntrinsicHeightParser(); | ||
|
|
||
| @override | ||
| String get type => StacIntrinsicHeight().type; | ||
|
|
||
| @override | ||
| StacIntrinsicHeight getModel(Map<String, dynamic> json) => | ||
| StacIntrinsicHeight.fromJson(json); | ||
|
|
||
| @override | ||
| Widget parse(BuildContext context, StacIntrinsicHeight model) { | ||
| return IntrinsicHeight(child: model.child.parse(context)); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
packages/stac/lib/src/parsers/widgets/stac_intrinsic_width/stac_intrinsic_width_parser.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:stac/src/parsers/core/stac_widget_parser.dart'; | ||
| import 'package:stac_framework/stac_framework.dart'; | ||
| import 'package:stac_core/widgets/intrinsic_width/stac_intrinsic_width.dart'; | ||
|
|
||
| class StacIntrinsicWidthParser extends StacParser<StacIntrinsicWidth> { | ||
| const StacIntrinsicWidthParser(); | ||
|
|
||
| @override | ||
| String get type => StacIntrinsicWidth().type; | ||
|
|
||
| @override | ||
| StacIntrinsicWidth getModel(Map<String, dynamic> json) => | ||
| StacIntrinsicWidth.fromJson(json); | ||
|
|
||
| @override | ||
| Widget parse(BuildContext context, StacIntrinsicWidth model) { | ||
| return IntrinsicWidth( | ||
| stepWidth: model.stepWidth, | ||
| stepHeight: model.stepHeight, | ||
| child: model.child.parse(context), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.