Overview
Stac theming works similarly to Flutter’s built-in theming system. You define themes usingStacTheme objects and apply them to your application using StacApp. The framework supports multiple ways to load themes:
- Cloud Themes (Recommended) - Fetch themes from Stac Cloud by name
- Network Themes - Load themes over HTTP using
StacNetworkRequest - JSON Themes - Parse themes from JSON data
Using StacApp with Themes
To use themes in your Stac application, replaceMaterialApp with StacApp and pass your theme using the StacAppTheme wrapper:
Theme Sources
1. Cloud Themes (Recommended)
Fetch themes from Stac Cloud by name. This is the recommended approach as it allows themes to be managed server-side and updated without app updates. Themes are cached locally for offline access and performance.Workflow: Generate and Deploy Themes
To use Cloud themes, you first need to:- Define your themes in your
stac/directory using@StacThemeRefannotation - Generate JSON from your DSL themes using the Stac CLI
- Deploy to Stac Cloud using
stac deploy
stac/app_theme.dart:
- Build your project
- Process all
@StacScreenannotated screens and@StacThemeRefannotated themes - Generate JSON files for each screen and theme
- Upload all generated files to Stac Cloud
StacAppTheme wrapper automatically fetches the theme from Stac Cloud using the provided name. Themes are cached intelligently to minimize network requests.
You can also use DSL themes directly by passing aStacThemeobject toStacAppTheme.dsl(theme: myTheme). When using themes directly, the@StacThemeRefannotation is not needed. The annotation is only required when you want to deploy themes to Stac Cloud usingstac deploy.
2. Network Themes
Load themes over HTTP using aStacNetworkRequest. This allows you to fetch themes from any API endpoint:
3. JSON Themes
Parse themes directly from JSON data. Useful when themes are stored locally or received from other sources:Theme Structure
AStacTheme consists of several components: