Skip to main content
The Stac SetValue widget allows you to set multiple key-value pairs in the application’s state and optionally render a child widget. It’s useful for managing application state through JSON configuration.

Properties

PropertyTypeDescription
valuesList<Map<String, dynamic>>List of key-value pairs to set in the application state.
childStacWidgetOptional child widget to render after the values are set.
Each item in values should contain:
  • key: The state key to set
  • value: The value to assign

Example

StacSetValue(
  values: [
    {'key': 'userName', 'value': 'John Doe'},
    {'key': 'isLoggedIn', 'value': true},
  ],
  child: StacText(data: 'Welcome!'),
)

Initializing State on Screen Load

Use StacSetValue to initialize state when a screen loads:
StacScaffold(
  body: StacSetValue(
    values: [
      {'key': 'currentPage', 'value': 'home'},
      {'key': 'selectedTab', 'value': 0},
      {'key': 'filters', 'value': {'category': 'all', 'sortBy': 'date'}},
    ],
    child: StacColumn(
      children: [
        StacText(data: 'Home Page'),
        // ... rest of the UI
      ],
    ),
  ),
)

Reading State Values

After setting values with StacSetValue, you can read them using placeholder syntax {{key}}:
StacSetValue(
  values: [
    {'key': 'greeting', 'value': 'Hello'},
    {'key': 'user.name', 'value': 'Alice'},
  ],
  child: StacText(data: '{{greeting}}, {{user.name}}!'),
)
For action-based state updates (e.g., on button press), see StacSetValueAction.