applyVariants method

  1. @override
Style applyVariants(
  1. List<Variant> selectedVariants
)
override

Selects multiple Variant instances and returns a new Style with the selected variants.

If the applyVariants list is empty, returns this mix without any changes. Otherwise, the method merges the attributes of the selected variants into a new Style instance.

Example: final outlinedVariant = Variant('outlined'); final smallVariant = Variant('small'); final style = Style( attr1, attr2, outlinedVariant(attr3, attr4), smallVariant(attr5), ); final outlinedSmallMix = style.applyVariants(outlinedVariant, smallVariant);


In this example:
- Two `Variant` instances `outlinedVariant` and `smallVariant` are created.
- An initial `Style` instance `style` is created with `attr1` and `attr2`, along with the two variants.
- The `applyVariants` method is called on the `Style` instance with a list of `outlinedVariant` and `smallVariant` as the argument.
- The `applyVariants` method returns a new `Style` instance `outlinedSmallMix` with the attributes of the selected variants merged.
- The resulting `outlinedSmallMix` is equivalent to `Style(attr1, attr2, attr3, attr4, attr5)`.

Note:
The attributes from the selected variants (`attr3`, `attr4`, and `attr5`) are not applied to the `Style` instance until the `applyVariants` method is called.

Implementation

@override
Style applyVariants(List<Variant> selectedVariants) {
  final newStyle = super.applyVariants(selectedVariants);

  return AnimatedStyle._(
    styles: newStyle.styles,
    variants: newStyle.variants,
    animated: animated,
  );
}