Prerequisites
Before rendering any Stac widgets, you must initialize Stac in your application:Rendering Methods
1. From Stac Cloud (Stac Widget)
The most common approach for server-driven UI is fetching screens from Stac Cloud using the Stac widget.
Usage
routeName and renders it.
Dart Source Code
Thehome_screen is defined in your /stac folder as a Dart file. Here’s an example:
stac/home_screen.dart:
stac deploy, this Dart code is converted to JSON and uploaded to Stac Cloud, making it available via Stac(routeName: 'home_screen').
Properties
Example
When to Use
- ✅ Production apps using Stac Cloud
- ✅ Dynamic content that changes server-side
- ✅ A/B testing and experimentation
- ✅ Apps that need instant updates without app store approval
2. From JSON (Stac.fromJson)
Render a widget directly from a JSON map. Useful for testing, prototyping, or when you have JSON in memory.
Usage
Properties
Example
When to Use
- ✅ Testing and development
- ✅ Prototyping with hardcoded JSON
- ✅ Rendering widgets from local variables
- ✅ Converting existing JSON data to widgets
3. From Assets (Stac.fromAssets)
Load and render widgets from JSON files bundled with your app. Perfect for static content or offline-first scenarios.
Usage
Properties
Setup
First, add your JSON file topubspec.yaml:
Example
When to Use
- ✅ Static content that doesn’t change
- ✅ Offline-first applications
- ✅ Fallback screens when network fails
- ✅ Demo apps and prototypes
4. From Network (Stac.fromNetwork)
Fetch and render widgets from any HTTP endpoint. Provides more control than Stac Cloud and works with your own API.
Usage
Properties
StacNetworkRequest Properties
Example
POST Request Example
When to Use
- ✅ Custom API endpoints
- ✅ Server-side rendering
- ✅ Dynamic content based on user data
- ✅ Multi-tenant applications
Comparison
Best Practices
- Always provide loading states: Users should know content is loading.
- Handle errors gracefully: Show meaningful error messages and retry options.
- Use appropriate method: Choose the rendering method that fits your use case.
- Validate JSON: Ensure your JSON follows Stac schema before rendering.