replaceAllWhere method

  1. @useResult
FWidgetStateMap<T> replaceAllWhere(
  1. Set<WidgetState> states,
  2. T replace(
    1. T
    )
)

Creates a new FWidgetStateMap where all values associated with constraints satisfied by states are replaced with the result of calling replace on the original value.

Where possible, it is strongly recommended to use the CLI to generate a style and directly modify its FWidgetStateMap fields instead.

Example

final property = FWidgetStateMap<Color>({
  WidgetState.pressed: Colors.blue,
  WidgetState.hovered: Colors.green,
});

// Create a new property with darker colors for pressed and hovered states.
final darkened = property.replaceAllWhere(
  {WidgetState.pressed, WidgetState.hovered},
  (color) => color.withOpacity(0.7),
);

Implementation

@useResult
FWidgetStateMap<T> replaceAllWhere(Set<WidgetState> states, T Function(T) replace) => FWidgetStateMap({
  for (final e in _constraints.entries) e.key: e.key.isSatisfiedBy(states) ? replace(e.value) : e.value,
});