Skip to main content
NextYou're reading unreleased docs. Features and APIs may change before release.View latestv1.1.x
Back to Flutter

FlowVariablesForm

The FlowVariablesForm widget lets a delegated admin override the variables a flow declares for their organization unit. It loads the variables the flow shares with the unit, the values the unit has set, and what the unit may change, shows them as a form, and saves the values that differ from their defaults.

For a shared flow, a variable is offered to a unit only when a sharing policy names it. A variable the unit may not set is shown as set by its owner. This form saves the overrides of a unit the flow was shared with, not the owner's defaults. Change the defaults in the flow's VARIABLES node.

FlowVariablesForm requires a ThunderIDProvider ancestor. The signed-in user's access token needs the permissions the server requires to read and update the flow's variables.

Note

The widget strings are available in English only. The Flutter SDK ships a single built-in string bundle, so the other locales that the iOS and Android SDKs support are not available here.

Usage​

dart
import 'package:thunderid_flutter/thunderid_flutter.dart';

class FlowSettings extends StatelessWidget {
const FlowSettings({super.key, required this.flowId, required this.ouId});

final String flowId;
final String ouId;

@override
Widget build(BuildContext context) {
return FlowVariablesForm(
flowId: flowId,
ouId: ouId,
onSaved: (values) => debugPrint('Saved'),
);
}
}

To let the admin pick the flow first, pair it with SharedFlowList.

Parameters​

ParameterTypeRequiredDescription
flowIdString✅Identifier of the flow whose variables are configured.
ouIdString✅The organization unit the overrides belong to.
onSavedValueChanged<FlowVariableValues>?❌Called with the unit's values after they are saved.
onCancelVoidCallback?❌Called when the admin taps Cancel. The button appears only when this is set.
onCreateConnectionVoidCallback?❌Called when the admin asks to create a connection from the hint under a connection variable. Without it, the hint does not offer one.
readOnlybool❌Shows the variables without letting them be changed. Defaults to false.
ouNameString?❌The name of the organization unit, used in the notice and the connection hint.
ownerNameString?❌The name of whoever owns the flow, shown on a variable the unit may not set.
showScopeNoticebool❌Shows a notice that the settings apply to the organization unit only. Defaults to false.
titleString?❌Heading of the form.
descriptionString?❌Text under the heading.
preferencesThunderIDPreferences?❌Internationalization preferences.
builderAdminWidgetBuilder<FlowVariablesFormState>?❌Builds custom UI in place of the default form. See Custom Rendering.

FlowVariableValues is a Map<String, Object> keyed by the variable's identifier. Each value is a String, a num, or a bool. Only the values that differ from their defaults are saved. A variable left at its default keeps following the default, even when the owner changes it later.

Custom Rendering​

Pass a builder to build the form with any UI while keeping the SDK's validation and rules. FlowVariablesForm still loads and saves the data, and passes the current state to the builder as a FlowVariablesFormState.

dart
FlowVariablesForm(
flowId: flowId,
ouId: ouId,
builder: (context, state) {
return Column(
children: [
for (final definition in state.variables)
if (state.getRule(definition).editable)
TextField(
decoration: InputDecoration(
labelText: definition.label ?? definition.identifier,
errorText: state.errors[definition.identifier],
),
onChanged: (text) => state.onChanged(definition.identifier, text),
)
else
Text('${definition.label ?? definition.identifier}: set by owner'),
FilledButton(
onPressed: state.isValid && !state.isSubmitting ? state.submit : null,
child: const Text('Save'),
),
],
);
},
)

FlowVariablesFormState Properties​

PropertyTypeDescription
variablesList<FlowVariableDefinition>The variables to render.
valuesFlowVariableValuesThe current value of each variable, keyed by identifier.
errorsMap<String, String>The translated message to show under each invalid variable, keyed by identifier. A variable appears once it was changed or a submit was attempted.
getRuleResolvedFlowVariableRule Function(FlowVariableDefinition)What the unit may do with a variable: whether it can set its own value, and the default it starts from.
getOptionsList<FlowVariableOption> Function(FlowVariableDefinition)The choices of a select variable, narrowed to what the unit may pick.
onChangedvoid Function(String identifier, Object value)Sets the value of one variable.
resetToDefaultsVoidCallbackReturns every variable to its default.
isValidboolWhether every variable the unit may set holds a valid value.
isSubmittingboolWhether a submission is in progress.
errorString?The form-level error, or null.
submitVoidCallbackSubmits the current values. Does nothing while they are not valid.
onCancelVoidCallback?The onCancel parameter.

BaseFlowVariables​

BaseFlowVariables is the presentational form. It holds no data of its own: pass the variables and handle the submission. Use it to preview a flow's variables or to build a form from data you load yourself.

dart
BaseFlowVariables(variables: variables)

Without overlay, every variable is editable. Without onSubmit, the form has no save button.

BaseFlowVariables Parameters​

ParameterTypeRequiredDescription
variablesList<FlowVariableDefinition>✅The variables to render, as the flow declares them.
connectionsList<ConnectionInstance>❌The connections a CONNECTION_SELECT variable can take. Defaults to none.
initialValuesFlowVariableValues?❌The values the form starts with, over each variable's default. A variable left out starts at its default.
overlayResolvedOverlay?❌What the unit may do with each variable, as getFlowOverlayRules returns it.
onSubmitvoid Function(FlowVariableValues values, FlowVariableValues overrides)?❌Called when the form is submitted and valid. values holds every value. overrides holds the values of the variables the unit may set that differ from their default.
onChangeValueChanged<FlowVariableValues>?❌Called with every value after one changes.
onCancelVoidCallback?❌Called when the admin taps Cancel.
onCreateConnectionVoidCallback?❌Called when the admin asks to create a connection from the hint under a connection variable.
isSubmittingbool❌Disables the form and shows a loading state on the save button. Defaults to false.
errorString?❌An already-translated error message. Never pass the server's text here.
readOnlybool❌Shows the variables without letting them be changed. Defaults to false.
ouNameString?❌The name of the organization unit, used in the notice and the connection hint.
ownerNameString?❌The name of whoever owns the flow, shown on a variable the unit may not set.
showScopeNoticebool❌Shows a notice that the settings apply to the organization unit only. Defaults to false.
titleString?❌Heading of the form.
descriptionString?❌Text under the heading.
preferencesThunderIDPreferences?❌Internationalization preferences.
builderAdminWidgetBuilder<FlowVariablesFormState>?❌Builds custom UI in place of the default form.

FlowVariableField​

FlowVariableField renders one variable in a card with its label, description, status, and the input its type calls for. BaseFlowVariables uses it for each variable, and you can use it to lay out the variables yourself.

ParameterTypeRequiredDescription
definitionFlowVariableDefinition✅The variable to render.
valueObject?✅The current value.
onChangedValueChanged<Object>✅Called when the value changes.
defaultValueObject?❌The value the variable falls back to. The field is marked customized while value differs.
editablebool❌Whether the unit may set its own value. A variable it may not set is shown as set by its owner. Defaults to true.
disabledbool❌Disables the input. Defaults to false.
errorString?❌The message to show under the input.
hintWidget?❌Extra content under the input.
optionsList<FlowVariableOption>❌The choices of a SELECT or CONNECTION_SELECT.
ownerNameString?❌Who set the variable, shown while it is not editable.
preferencesThunderIDPreferences?❌Internationalization preferences.

Each type renders its own input:

Variable typeInput
TEXT_INPUT, EMAIL_INPUT, PHONE_INPUT, NUMBER_INPUT, DATE_INPUTText field with the keyboard the type calls for
BOOLEAN_INPUTSwitch
SELECT, CONNECTION_SELECTDropdown. The first entry shows the default, for example "Use the default: Dark", and returns the variable to it.

Load the Data Yourself​

FlowVariablesController loads the data behind the form, for a screen built entirely by your app. It is the counterpart of the React SDK's useFlowVariables hook. It loads on creation and notifies its listeners on every change. Dispose it when done.

dart
class CustomSettings extends StatefulWidget {
const CustomSettings({super.key, required this.flowId, required this.ouId});

final String flowId;
final String ouId;

@override
State<CustomSettings> createState() => _CustomSettingsState();
}

class _CustomSettingsState extends State<CustomSettings> {
FlowVariablesController? _controller;

@override
void didChangeDependencies() {
super.didChangeDependencies();
_controller ??= FlowVariablesController(
ThunderIDProvider.of(context).managementResources,
flowId: widget.flowId,
ouId: widget.ouId,
);
}

@override
void dispose() {
_controller?.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
final controller = _controller!;
return ListenableBuilder(
listenable: controller,
builder: (context, _) {
if (!controller.isLoaded) return const CircularProgressIndicator();
return BaseFlowVariables(
variables: controller.definitions,
connections: controller.connections,
initialValues: controller.overrides,
overlay: controller.overlay,
isSubmitting: controller.isSaving,
onSubmit: (_, overrides) => controller.save(overrides),
);
},
);
}
}
Property or methodDescription
flowThe flow as the organization unit sees it.
definitionsThe variables the flow declares for the unit.
overridesThe values the unit has set. A variable it has not set is absent, and its default applies.
overlayWhat the unit may do with each variable.
connectionsThe connections a CONNECTION_SELECT variable can take. Empty until loaded, and when no variable needs them.
isLoaded, isLoading, errorWhether everything has arrived, whether a load is in progress, and why it could not be loaded.
isSaving, saveErrorWhether a save is in progress, and why the last one failed.
save(values)Replaces the unit's values. A variable left out returns to its default. Resolves with the saved values, or null when the save failed.

Flow Variable Helpers​

The form is built on these top-level functions. Use them with any UI.

FunctionDescription
getFlowVariableDefinitions(flow)Reads the variables a flow declares. A flow shared with the unit lists them in variables. A flow the unit owns declares them on its VARIABLES node. Returns an empty list when the flow declares none.
resolveFlowVariableRule(definition, [overlay])Works out what the unit may do with a variable. Returns a ResolvedFlowVariableRule with editable, defaultValue, allowedValues, and excludedValues. Without an overlay, every variable is editable.
getFlowVariableOptions(definition, {connections, allowedValues, excludedValues})Lists what a select variable can take. A SELECT takes the values it declares. A CONNECTION_SELECT takes the connections that match its category and connectionTypes. Any other type returns an empty list.
validateFlowVariableValue(definition, value)Checks a value against the variable's type, options, and rules. Returns a FlowVariableValidationError, or null when the value is valid. A BOOLEAN_INPUT is valid when it is a boolean or not set. Every other type requires a value.
dart
final management = ThunderIDProvider.of(context).management;

final flow = await management.getFlow(flowId, ouId: ouId);
final overlay = await management.getFlowOverlayRules(flowId, ouId);

for (final definition in getFlowVariableDefinitions(flow)) {
final rule = resolveFlowVariableRule(definition, overlay);
final problem = validateFlowVariableValue(definition, rule.defaultValue);
}

The owning unit does not use these helpers: the server rejects an override saved for it with HTTP 400, so it changes defaults in the flow's VARIABLES node.

A SELECT value is validated by its text, as the server does, so "true" is valid for an option true.

The FlowVariableValidationErrorCode values are:

CodeMeaning
requiredThe value is empty.
invalidThe value is not valid for the type, such as text that is not an email address or a number that is not numeric.
minA number is below min.
maxA number is above max.
notOptionA SELECT value is not one of its options.
minLengthText is shorter than a minLength rule allows.
maxLengthText is longer than a maxLength rule allows.
patternText does not match a regex rule.

For the three text rules, the error also carries the rule's message when it has one. The text rules are checked for TEXT_INPUT only, so a value can pass here and still be rejected by the server, which validates again on save. A regex rule that cannot be compiled is skipped, and the server judges it.

FlowVariableDefinition​

PropertyTypeDescription
identifierStringName of the variable, which a {{var(name)}} placeholder uses.
typeStringThe input the variable is edited with. Use the FlowVariableTypes constants: textInput, emailInput, phoneInput, numberInput, dateInput, booleanInput, select, or connectionSelect.
labelString?Display name.
descriptionString?Help text.
defaultValueObject?The value the variable has until another is set.
optionsList<Object>For a SELECT: the values it can take.
categoryString?For a CONNECTION_SELECT: the kind of connection it takes. The server accepts only IDENTITY_PROVIDER.
connectionTypesList<String>For a CONNECTION_SELECT: limits it to these vendors. The server accepts google, github, oidc, and oauth.
min, maxnum?For a NUMBER_INPUT: the lowest and highest value.
validationList<FlowVariableValidationRule>Rules a text value has to meet.

Internationalization​

The labels, errors, and notices come from the admin.flowVariables keys in the SDK's built-in strings, which are English only. Override them through preferences.

Explore with AI

ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.