What is Stac DSL?
Stac DSL (Domain-Specific Language) is a Dart-based language that allows you to write Server-Driven UI using familiar Flutter-like syntax. Instead of writing JSON directly, you write your UI in Dart usingStacWidget classes, and Stac automatically converts it to JSON for deployment.
Why We Built It?
Writing complex UIs in raw JSON can be:- Error-prone: Missing commas, brackets, and typos are common
- Hard to maintain: No IDE support, autocomplete, or type checking
- Difficult to debug: No compile-time errors or helpful error messages
- Lacks reusability: Hard to create reusable components and helpers
- Type safety: Full Dart type checking and IDE support
- Better DX: Autocomplete, syntax highlighting, and refactoring
- Reusability: Create helper functions and reusable components
- Maintainability: Easier to read, write, and modify complex UIs
- Compile-time validation: Catch errors before deployment
How to Use Stac DSL?
Stac DSL follows Flutter-like definitions and class names withStac prefixed. For example, Scaffold becomes StacScaffold, Column becomes StacColumn, and Text becomes StacText.
Screens are defined in the stac/screens/ folder (or directly in stac/). Each screen is a Dart function annotated with @StacScreen. Note that the Dart function should return a StacWidget.
Themes are defined in the stac/theme/ folder using the @StacThemeRef annotation. The function should return a StacTheme.
Folder Structure
A typical Stac project with DSL follows this structure:Writing Screens
Screens are defined in thestac/screens/ folder (or directly in stac/). Each screen is a Dart function annotated with @StacScreen:
Writing Themes
Themes are defined in thestac/theme/ folder using the @StacThemeRef annotation:
Annotations
@StacScreen
Marks a function as a Stac screen definition. The function must return a StacWidget.
Properties:
screenName(required): The unique identifier for this screen, used in navigation and deployment
@StacThemeRef
Marks a getter as a Stac theme definition. The getter must return a StacTheme.
Properties:
name(required): The unique identifier for this theme
Build & Deploy
Building (Dart → JSON)
Thestac build command converts your Dart DSL code to JSON:
- Scans the
stac/folder for@StacScreenand@StacThemeRefannotations - Executes each annotated function/getter to get the
StacWidgetorStacTheme - Converts the result to JSON using
.toJson() - Saves JSON files to the
build/folder
Deploying to Stac Cloud
Thestac deploy command builds your DSL and uploads it to Stac Cloud:
- Runs
stac build(unless--skip-buildis used) - Uploads all JSON files from
build/to Stac Cloud - Makes screens available via
Stac(routeName: 'screen_name')in your app
Example: Complete Screen
Here’s a complete example showing a screen with navigation, network requests, and theming:Reference: DSL Files and Output
Input: Dart DSL (stac/home_screen.dart)
Output: JSON (build/screens/home_screen.json)
Usage in App
Once deployed, use the screen in your Flutter app:Next Steps
- Learn about available widgets you can use in DSL
- Explore actions for handling user interactions
- Check out the movie app example for a complete DSL project
- Read about theming for customizing your app’s appearance