applyVariant property

SpreadFunctionParams<Variant, Style> get applyVariant

Selects a single or positional params list of Variant and returns a new Style with the selected variants.

If the applyVariant is not initially part of the Style, this method returns this mix without any changes. Otherwise, the method merges the attributes of the selected applyVariant into a new Style instance.

Example:

final outlined = Variant('outlined');
final style = Style(
  attr1,
  attr2,
  outlined(
    attr4,
    attr5,
  ),
);
final updatedStyle = style.applyVariant(outlined);

In this example:

  • An outlined instance outlined is created to represent an outlined button styling.
  • An initial Style instance style is created with attr1 and attr2, along with the outlined.
  • The variant method is called on the Style instance with outlined as the argument.
  • The variant method returns a new Style instance updatedStyle with the attributes of the selected variant merged.
  • The resulting updatedStyle is equivalent to Style(attr1, attr2, attr4, attr5).

Note: The attributes from the selected variant (attr4 and attr5) are not applied to the Style instance until the applyVariant method is called.

Implementation

SpreadFunctionParams<Variant, Style> get applyVariant =>
    SpreadFunctionParams(applyVariants);