|
| 1 | +--- |
| 2 | +title: "Use Stac in VS Code" |
| 3 | +description: "Install and configure the Stac extension for VS Code. Get live preview, wrap quick-fixes, and snippets for Server-Driven UI — right inside your editor." |
| 4 | +--- |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | + |
| 8 | +- **Flutter SDK** with Dart `3.9.2+` |
| 9 | +- A Flutter project using the [Stac](https://stac.dev) framework |
| 10 | + |
| 11 | +## Install the extension |
| 12 | + |
| 13 | +Click the link for your IDE to install directly: |
| 14 | + |
| 15 | +- [Install for VS Code](vscode:extension/StacDev.stac-vscode) |
| 16 | +- [Install for Cursor](cursor:extension/StacDev.stac-vscode) |
| 17 | +- [Install for Antigravity](antigravity:extension/StacDev.stac-vscode) |
| 18 | + |
| 19 | +Or in VS Code, press `Cmd+Shift+X` (Mac) or `Ctrl+Shift+X` (Windows/Linux) to open the Extensions view, search for "Stac", and click **Install**. |
| 20 | + |
| 21 | +## Get started |
| 22 | + |
| 23 | +1. **Open a Stac project** — open any Flutter project that uses the Stac framework. |
| 24 | +2. **Open the Command Palette** — press `⌘⇧P` (Mac) or `Ctrl+Shift+P` (Windows / Linux) and type **"Stac"**. |
| 25 | +3. **Launch a live preview** — run **`Stac: Open Preview`** to open a side-by-side preview of the active `@StacScreen`. |
| 26 | + |
| 27 | +<Frame> |
| 28 | + <img src="https://raw.githubusercontent.com/StacDev/stac/dev/tools/stac-vscode/media/stac_preview.png" alt="Stac Live Preview" /> |
| 29 | +</Frame> |
| 30 | + |
| 31 | +## Use live preview |
| 32 | + |
| 33 | +The preview panel renders your `@StacScreen` in real time and updates automatically on save. |
| 34 | + |
| 35 | +- **Device toggles** — switch between Android, iOS, and Web viewports. |
| 36 | +- **Theme picker** — preview with any `@StacThemeRef` theme defined in your project. |
| 37 | +- **Auto-refresh** — every time you save, the preview re-renders. Disable this with the `stacVscode.preview.autoRefreshOnSave` setting. |
| 38 | + |
| 39 | +### Preview commands |
| 40 | + |
| 41 | +| Command | Description | |
| 42 | +| --- | --- | |
| 43 | +| `Stac: Open Preview` | Open the live preview panel for the active screen | |
| 44 | +| `Stac: Select Preview Screen` | Switch to a different screen in the current file | |
| 45 | +| `Stac: Stop Preview` | Stop the preview host process | |
| 46 | + |
| 47 | +## Use wrap quick-fixes |
| 48 | + |
| 49 | +Place your cursor on any Stac widget expression and press `⌘.` (Mac) or `Ctrl+.` (Windows / Linux) to wrap it with a preset widget: |
| 50 | + |
| 51 | +`StacContainer` · `StacPadding` · `StacCenter` · `StacAlign` · `StacSizedBox` · `StacExpanded` |
| 52 | + |
| 53 | +Select **Wrap with Stac widget…** to wrap with any custom Stac widget class in your project. |
| 54 | + |
| 55 | +<Tip> |
| 56 | + You can customise which preset wrappers appear in the quick-fix menu with the `stacVscode.wrapPresets` setting, or disable wrap actions entirely with `stacVscode.enableWrapQuickFix`. |
| 57 | +</Tip> |
| 58 | + |
| 59 | +## Use snippets |
| 60 | + |
| 61 | +In files containing `@StacScreen`, `@StacThemeRef`, or `package:stac_core`, the following snippets are available: |
| 62 | + |
| 63 | +| Prefix | What it creates | |
| 64 | +| --- | --- | |
| 65 | +| `stac screen` | A new screen template | |
| 66 | +| `stac theme` | A new theme template | |
| 67 | + |
| 68 | +Snippets can be toggled with the `stacVscode.enableSnippets` setting. |
| 69 | + |
| 70 | +## Commands and shortcuts |
| 71 | + |
| 72 | +Open the Command Palette (`⌘⇧P` / `Ctrl+Shift+P`) and type **"Stac"** to see all available commands: |
| 73 | + |
| 74 | +| Command | Description | |
| 75 | +| --- | --- | |
| 76 | +| `Stac: Open Preview` | Open the live preview panel | |
| 77 | +| `Stac: Select Preview Screen` | Switch screen in the current file | |
| 78 | +| `Stac: Stop Preview` | Stop the preview host | |
| 79 | +| `Stac: Regenerate Catalog` | Rebuild the widget catalog from `stac_core` | |
| 80 | + |
| 81 | +## Configure settings |
| 82 | + |
| 83 | +Open VS Code settings (`⌘,` / `Ctrl+,`) and search **"Stac"** to customise the extension. |
| 84 | + |
| 85 | +### Extension settings |
| 86 | + |
| 87 | +| Setting | Default | Description | |
| 88 | +| --- | --- | --- | |
| 89 | +| `stacVscode.enableWrapQuickFix` | `true` | Enable wrap quick-fix actions | |
| 90 | +| `stacVscode.wrapPresets` | All presets | Preset wrappers shown in the quick-fix menu | |
| 91 | +| `stacVscode.enableSnippets` | `true` | Enable `stac screen` / `stac theme` snippets | |
| 92 | +| `stacVscode.preview.enable` | `true` | Enable preview commands | |
| 93 | +| `stacVscode.preview.autoRefreshOnSave` | `true` | Refresh the preview on save | |
| 94 | +| `stacVscode.preview.jsonStrategy` | `runnerThenBuild` | JSON generation strategy | |
| 95 | +| `stacVscode.preview.hostPort` | `47841` | Local preview host port | |
| 96 | +| `stacVscode.preview.startupTimeoutMs` | `120000` | Host startup timeout (ms) | |
| 97 | + |
| 98 | +## Troubleshooting |
| 99 | + |
| 100 | +### Preview won't start |
| 101 | + |
| 102 | +1. Open **Output → Stac Preview** for detailed logs. |
| 103 | +2. Ensure your project builds successfully with `flutter run`. |
| 104 | +3. Confirm the active file contains a `@StacScreen` annotation. |
| 105 | +4. Try restarting the preview host by running **`Stac: Stop Preview`**, then **`Stac: Open Preview`**. |
| 106 | + |
| 107 | +### Extension won't install |
| 108 | + |
| 109 | +- Ensure you have a compatible version of VS Code (1.80.0 or later). |
| 110 | +- Check that VS Code has permission to install extensions. |
| 111 | +- Try installing directly from the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=StacDev.stac-vscode). |
| 112 | + |
| 113 | +## Uninstall the extension |
| 114 | + |
| 115 | +1. Open the Extensions view (`⇧⌘X` / `Ctrl+Shift+X`). |
| 116 | +2. Search for **"Stac"**. |
| 117 | +3. Click **Uninstall**. |
| 118 | + |
| 119 | +<Card title="Report an Issue" icon="github" href="https://github.com/StacDev/stac/issues"> |
| 120 | + Found a bug or have a feature request? Open an issue on GitHub. |
| 121 | +</Card> |
0 commit comments