StatedWidget.map constructor
Creates a StatedWidget using a map-based state configuration.
Provides a flexible approach where states are defined using a map with keys representing state identifiers and values being the corresponding widgets. This approach is useful when states are determined dynamically or when working with custom state types.
The child parameter serves as a fallback when no matching state
is found in the states map. State resolution prioritizes exact
matches in the provided map.
Parameters:
states(Map<Object, Widget>, required): Map of state-to-widget mappingschild(Widget?, optional): Fallback widget when no state matches
Example:
StatedWidget.map(
states: {
WidgetState.selected: Icon(Icons.check_circle, color: Colors.green),
WidgetState.error: Icon(Icons.error, color: Colors.red),
'custom': Icon(Icons.star, color: Colors.blue),
},
child: Icon(Icons.circle_outlined),
)
Implementation
const factory StatedWidget.map({
Key? key,
required Map<Object, Widget> states,
Widget? child,
}) = _MapStatedWidget;