Documentation Index
Fetch the complete documentation index at: https://docs.stac.dev/llms.txt
Use this file to discover all available pages before exploring further.
The StacSetValueAction allows you to set or update values in the application state. It’s useful for updating state in response to user interactions like button presses.
Properties
| Property | Type | Description |
|---|
| values | List<Map<String, dynamic>> | List of key-value pairs to write to the application state. |
| action | StacAction | Optional action to execute after the values are set. |
Each item in values should contain:
key: The state key to set
value: The value to assign
Example
StacSetValueAction(
values: [
{'key': 'isLoggedIn', 'value': true},
{'key': 'token', 'value': 'abc123'},
],
action: StacNavigateAction(routeName: '/home'),
)
StacElevatedButton(
child: StacText(data: 'Toggle Dark Mode'),
onPressed: StacSetValueAction(
values: [
{'key': 'isDarkMode', 'value': true},
],
),
)
Update Multiple Values with Follow-up Action
StacElevatedButton(
child: StacText(data: 'Complete Order'),
onPressed: StacSetValueAction(
values: [
{'key': 'order.status', 'value': 'completed'},
{'key': 'order.completedAt', 'value': '2024-01-15T10:30:00Z'},
{'key': 'cart.items', 'value': []},
],
action: StacSnackBarAction(
content: StacText(data: 'Order completed successfully!'),
behavior: SnackBarBehavior.floating,
),
),
)
Chaining with Network Request
StacMultiAction(
sync: true,
actions: [
StacSetValueAction(
values: [
{'key': 'isLoading', 'value': true},
],
),
StacNetworkRequestAction(
url: 'https://api.example.com/data',
method: Method.get,
results: [
StacNetworkResult(
statusCode: 200,
action: StacSetValueAction(
values: [
{'key': 'isLoading', 'value': false},
{'key': 'data', 'value': '{{response}}'},
],
),
),
],
),
],
)
For setting initial state when a screen loads (without an action trigger), use the StacSetValue widget instead.