defaultData property
A list of preselected choices that serve as the default selection when the widget is first built or when externally updated.
If defaultData is provided:
- The widget will initialize the selected state based on this list.
- When defaultData is changed externally at runtime (e.g., through a state management update),
the selection will automatically update and trigger onSelect with
isFromDefaultData = true
.
If defaultData is null
, no selection will be applied by default.
This is useful for syncing the selection state with an external source or for pre-filling selections when rendering the widget.
Example:
MySelectorWidget(
defaultData: [Choice(id: 1, label: 'Apple')],
onSelect: (choices, isFromDefaultData) {
if (isFromDefaultData) {
// Handle programmatic selection
} else {
// Handle user-initiated selection
}
},
)
Implementation
final List<Choice<T>>? defaultData;