Detecting classes in source files
Overview
Section titled “Overview”In Tailwind CSS, a build-time scanner detects which utility classes appear in your source files and generates only the CSS for those classes. This keeps the production CSS bundle small.
Style works differently — it resolves classes at runtime, not at build time.
How it works in Tailwind CSS
Section titled “How it works in Tailwind CSS”Tailwind’s build tool:
- Scans your source files for class strings
- Generates CSS only for detected classes
- Purges unused utilities from the bundle
This requires configuring content paths so the scanner knows where to look.
How it works in Style
Section titled “How it works in Style”Style’s approach:
- Class strings are passed to
Style('...')at runtime ClassParsersplits the string into tokens- Each token is routed to the appropriate
StyleResolver - Resolvers produce Flutter widget properties (
StyleSpec)
There is no build step and no tree-shaking of utilities. All resolvers are always available.
Implications
Section titled “Implications”| Aspect | Tailwind CSS | Style |
|---|---|---|
| Unused classes | Purged at build time | Resolvers always included |
| Dynamic classes | Must be complete strings | Fully dynamic — compose strings freely |
| Build configuration | content paths required | No configuration needed |
| String interpolation | Safe if full class appears in source | Always safe |
Dynamic class composition
Section titled “Dynamic class composition”Because Style resolves at runtime, you can compose class strings dynamically without restrictions:
// This works perfectly — no build-time scanning neededfinal isActive = true;final classes = 'p-4 rounded-lg ${isActive ? "bg-blue-500 text-white" : "bg-gray-100 text-gray-700"}';
Style(classes, child: Text('Item'))In Tailwind CSS, dynamic string construction can break the scanner. In Style, it’s always safe.
Performance
Section titled “Performance”Style caches parsed results, so repeated class strings resolve instantly:
// First call: parsed and cachedStyle('p-4 bg-white rounded-lg', child: ...)
// Subsequent calls with same string: cache hitStyle('p-4 bg-white rounded-lg', child: ...)The ClassParser is a singleton with a result cache, making repeated resolution essentially free.