Skip to content

Detecting classes in source files

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.


Tailwind’s build tool:

  1. Scans your source files for class strings
  2. Generates CSS only for detected classes
  3. Purges unused utilities from the bundle

This requires configuring content paths so the scanner knows where to look.


Style’s approach:

  1. Class strings are passed to Style('...') at runtime
  2. ClassParser splits the string into tokens
  3. Each token is routed to the appropriate StyleResolver
  4. Resolvers produce Flutter widget properties (StyleSpec)

There is no build step and no tree-shaking of utilities. All resolvers are always available.


AspectTailwind CSSStyle
Unused classesPurged at build timeResolvers always included
Dynamic classesMust be complete stringsFully dynamic — compose strings freely
Build configurationcontent paths requiredNo configuration needed
String interpolationSafe if full class appears in sourceAlways safe

Because Style resolves at runtime, you can compose class strings dynamically without restrictions:

// This works perfectly — no build-time scanning needed
final 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.


Style caches parsed results, so repeated class strings resolve instantly:

// First call: parsed and cached
Style('p-4 bg-white rounded-lg', child: ...)
// Subsequent calls with same string: cache hit
Style('p-4 bg-white rounded-lg', child: ...)

The ClassParser is a singleton with a result cache, making repeated resolution essentially free.