applyVariant property
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
outlinedinstanceoutlinedis created to represent an outlined button styling. - An initial
Styleinstancestyleis created withattr1andattr2, along with theoutlined. - The
variantmethod is called on theStyleinstance withoutlinedas the argument. - The
variantmethod returns a newStyleinstanceupdatedStylewith the attributes of the selected variant merged. - The resulting
updatedStyleis equivalent toStyle(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);