Skip to content

Conversation

@leoafarias
Copy link
Collaborator

Summary

  • Adds applyVariants() method to VariantStyleMixin for applying named variants to styles
  • Creates internal AppliedVariantsStyle wrapper class to carry pre-applied variants

Problem

Users could create NamedVariant and add them to styles via .variant(), but there was no API to activate them (issue #794).

Solution

Adds a simple applyVariants() method that returns a wrapped style which passes the specified variants to build() during resolution.

Usage

final style = BoxStyler()
  .variant(small, BoxStyler().width(50))
  .variant(large, BoxStyler().width(200));

// Apply the small variant
Box(style: style.applyVariants([small]))

Test plan

  • Added unit tests for applyVariants covering single/multiple variants, merging, and widget tree integration

Closes #794

Adds applyVariants() method to VariantStyleMixin that allows users to
apply named variants to styles. This addresses issue #794 where users
could create NamedVariant but had no way to activate them.

Usage:
```dart
final style = BoxStyler()
  .variant(small, BoxStyler().width(50))
  .variant(large, BoxStyler().width(200));

Box(style: style.applyVariants([small]))
```

Closes #794
@docs-page
Copy link

docs-page bot commented Dec 19, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/btwld/mix~800

Documentation is deployed and generated using docs.page.

@vercel
Copy link
Contributor

vercel bot commented Dec 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
mix-docs Ready Ready Preview, Comment Dec 19, 2025 3:26pm

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an applyVariants() method to the Mix framework that allows developers to pre-apply named variants to styles, addressing issue #794 where users could define named variants but had no API to activate them.

Key Changes:

  • Adds applyVariants() method to VariantStyleMixin for pre-applying named variants
  • Creates internal AppliedVariantsStyle wrapper class that stores and applies variants during resolution
  • Includes comprehensive test coverage for single/multiple variants, merging, and widget integration

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/mix/lib/src/style/mixins/variant_style_mixin.dart Adds the applyVariants() method with documentation and example usage
packages/mix/lib/src/core/internal/applied_variants_style.dart Implements internal wrapper class that carries pre-applied variants and combines them with runtime variants
packages/mix/test/src/style/mixins/variant_style_mixin_test.dart Adds comprehensive test suite covering single/multiple variants, merging, and widget tree integration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No way to apply variants in mix 2

2 participants