Skip to main content
Stac provides multiple ways to render widgets from JSON, each suitable for different scenarios. This guide covers all available rendering methods and when to use them.

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

This widget automatically fetches the screen JSON from Stac Cloud based on the routeName and renders it.

Dart Source Code

The home_screen is defined in your /stac folder as a Dart file. Here’s an example: stac/home_screen.dart:
After running 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 to pubspec.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

  1. Always provide loading states: Users should know content is loading.
  2. Handle errors gracefully: Show meaningful error messages and retry options.
  3. Use appropriate method: Choose the rendering method that fits your use case.
  4. Validate JSON: Ensure your JSON follows Stac schema before rendering.

Hybrid Approach