Skip to Content
Mix 2.0 is in development! You can access the Mix 1.0 docs here.
DocsEcosystemmix_tailwinds

mix_tailwinds

mix_tailwinds provides a Tailwind CSS-like utility syntax for styling Flutter widgets using Mix. Write class names such as flex, gap-4, and text-lg instead of composing stylers manually.

Treat this package as a proof of concept. The API is unstable and will change without notice.

Interactive Preview

Resolving preview metadata...

The card alert above demonstrates gradients, glassmorphism, badges, hover states, and nested flex layouts — all expressed through class name strings:

import 'package:flutter/material.dart'; import 'package:mix_tailwinds/mix_tailwinds.dart'; class CardAlert extends StatelessWidget { const CardAlert({super.key}); @override Widget build(BuildContext context) { return TwScope( child: Div( classNames: 'bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900 p-6', child: Div( classNames: 'bg-white/10 border border-white/20 rounded-3xl p-6 shadow-2xl', child: Div( classNames: 'flex items-start gap-4', children: [ Div( classNames: 'w-14 h-14 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 flex items-center justify-center border-2 border-purple-400', child: const Span( text: 'SM', classNames: 'text-white font-semibold text-lg', ), ), Div( classNames: 'flex-1 min-w-0', children: [ Div( classNames: 'flex items-center gap-2 mb-1', children: const [ H3( text: 'Sarah Mitchell', classNames: 'text-white font-semibold text-lg truncate', ), Span( text: 'Admin', classNames: 'px-2 py-0.5 bg-purple-500/30 text-purple-200 text-xs rounded-full font-medium', ), ], ), const P( text: 'Your profile changes are ready to publish. Review and confirm to update your public information.', classNames: 'text-slate-300 text-sm mb-4', ), Div( classNames: 'bg-white/5 rounded-xl p-3 mb-4 border border-white/10', child: Div( classNames: 'flex items-center gap-2 text-amber-300 text-sm', children: const [ Span(text: '\u26A0'), Span(text: 'This action cannot be undone'), ], ), ), Div( classNames: 'flex gap-3', children: [ Div( classNames: 'flex-1 px-4 py-2.5 bg-white/10 hover:bg-white/20 text-white rounded-xl font-medium border border-white/10 hover:border-white/20 flex items-center justify-center', child: const Span(text: 'Cancel'), ), Div( classNames: 'flex-1 px-4 py-2.5 bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-400 hover:to-pink-400 text-white rounded-xl font-medium shadow-lg flex items-center justify-center', child: const Span(text: 'Save Changes'), ), ], ), ], ), ], ), ), ), ); } }

The following resources point to the package registry and source code:

Install

From pub.dev:

dependencies: mix_tailwinds: 0.0.1-alpha.1

From the Git repository (latest unreleased changes):

dependencies: mix_tailwinds: git: url: https://github.com/btwld/mix.git path: packages/mix_tailwinds

Quick start

Wrap your app with TwScope, then use Div and Span to build layouts with Tailwind-like class names:

import 'package:flutter/material.dart'; import 'package:mix_tailwinds/mix_tailwinds.dart'; void main() { runApp( TwScope( child: MaterialApp( home: Scaffold( body: Center( child: Div( classNames: 'flex flex-col gap-4 p-6 bg-white rounded-xl shadow-md', children: [ Span( text: 'Hello mix_tailwinds', classNames: 'text-2xl font-bold text-gray-900', ), Span( text: 'Utility-first styling powered by Mix.', classNames: 'text-sm text-gray-600', ), ], ), ), ), ), ), ); }

This renders a white rounded card with a title and subtitle, using only class name strings.

Widget API

The following table lists all widgets provided by mix_tailwinds:

WidgetPurpose
TwScopeRoot wrapper. Provides TwConfig (scales, colors, breakpoints) and default typography to the widget tree.
DivContainer and layout element. Auto-detects whether to render as a flex container or a box based on class names.
SpanInline text element.
PBlock-level paragraph element.
H1H6Heading elements. No default styles applied (matches Tailwind Preflight behavior).
TruncatedPConvenience wrapper for text truncation in flex containers. Auto-applies flex-1 min-w-0.

All layout widgets accept a classNames string and an optional onUnsupported callback for unrecognized tokens:

Div( classNames: 'flex gap-4 unknown-class', onUnsupported: (token) => debugPrint('Unsupported: $token'), children: [...], )

Supported utility classes

Layout

UtilityDescription
flexEnable flex layout
flex-row, flex-colFlex direction
flex-wrap, flex-nowrap, flex-wrap-reverseFlex wrap behavior
flex-1, flex-auto, flex-initial, flex-noneFlex shorthand
grow, grow-0, shrink, shrink-0Flex grow/shrink
items-start, items-center, items-end, items-stretch, items-baselineCross-axis alignment
justify-start, justify-center, justify-end, justify-between, justify-around, justify-evenlyMain-axis alignment
self-auto, self-start, self-center, self-end, self-stretchSelf alignment
hidden, blockDisplay mode
overflow-hidden, overflow-visible, overflow-clipOverflow behavior

Spacing

UtilityScale
p-*, px-*, py-*, pt-*, pr-*, pb-*, pl-*Padding (0–96)
m-*, mx-*, my-*, mt-*, mr-*, mb-*, ml-*Margin (0–96, supports negative: -m-*)
gap-*, gap-x-*, gap-y-*Gap between flex children (0–96)

Sizing

UtilityScale
w-*, h-*Width/height (0–96, plus full, screen, auto)
min-w-*, min-h-*, max-w-*, max-h-*Min/max constraints
Fractional: w-1/2, h-1/3, w-2/5Percentage-based sizing

Typography

UtilityDescription
text-xs through text-9xlFont size (12px–128px)
font-thin through font-blackFont weight (100–900)
text-left, text-center, text-right, text-justify, text-start, text-endText alignment
uppercase, lowercase, capitalizeText transform
truncateText overflow ellipsis
leading-none through leading-looseLine height
tracking-tighter through tracking-widestLetter spacing

Colors

UtilityDescription
bg-*Background color
text-*Text color

Available color palettes: slate, gray, blue, purple, pink, red, amber, emerald, plus black, white, and transparent. Each palette includes shades from 50 to 950.

Borders

UtilityScale
border-*, border-t-*, border-r-*, border-b-*, border-l-*, border-x-*, border-y-*Border width (0, 1, 2, 4, 8)
rounded-*, rounded-t-*, rounded-b-*, rounded-l-*, rounded-r-*, rounded-tl-*, rounded-tr-*, rounded-bl-*, rounded-br-*Border radius (none–full)

Effects

UtilityDescription
shadow-none through shadow-2xlBox shadow
text-shadow-none through text-shadow-lgText shadow
blur-none through blur-3xlBlur filter

Transforms

UtilityScale
scale-*Transform scale (0–1.5)
rotate-*Rotation (0–180°, supports negative: -rotate-*)
translate-x-*, translate-y-*Translation (supports negative)

Animations

UtilityDescription
transition, transition-all, transition-colors, transition-opacity, transition-shadow, transition-transform, transition-noneTransition properties
duration-*Animation duration (0–1000ms)
delay-*Animation delay (0–1000ms)
ease-linear, ease-in, ease-out, ease-in-outEasing curves

Variants

Prefix any utility with a variant to apply it conditionally.

Responsive breakpoints

PrefixMin-width
sm:640px
md:768px
lg:1024px
xl:1280px
2xl:1536px
Div(classNames: 'flex flex-col md:flex-row gap-4', children: [...])

Interaction states

PrefixTriggers when
hover:Pointer hovers over the widget
active:Widget is pressed
focus:Widget has focus
disabled:Widget is disabled
group:Parent group state
group-hover:Parent group is hovered
Div( classNames: 'bg-blue-600 hover:bg-blue-700 active:bg-blue-800 text-white px-4 py-2 rounded-lg', child: Span(text: 'Click me'), )

Theme variants

PrefixApplies when
dark:Dark theme is active
light:Light theme is active

Composing variants

Combine multiple variant prefixes on a single token:

Div(classNames: 'bg-white md:hover:bg-blue-500 dark:bg-gray-900')

Special syntax

Arbitrary values

Use square brackets for values outside the default scale:

Div(classNames: 'bg-[#FF0000] p-[24px] w-[100px]')

Opacity modifiers

Append /<opacity> (0–100) to any color utility:

Div(classNames: 'bg-white/50 text-black/75')

Important flag

Prefix with ! to mark a utility as important (overrides other values during merge):

Div(classNames: '!font-bold')

Negative values

Prefix with - for margin and transform utilities:

Div(classNames: '-mt-4 -translate-x-8')

Defaults and typography configuration

mix_tailwinds applies default typography through TwScope using Mix’s token and text scope system. Prefer this over overriding ThemeData.textTheme when configuring default text styles.

TwScope injects a base text style into the widget tree so all text inherits consistent defaults. Configure typography through TwTextDefaults:

TwScope( config: TwConfig.standard().copyWith( textDefaults: TwTextDefaults( fontFamily: 'Inter', fontSize: 16, lineHeight: 1.5, letterSpacing: 0, fontWeight: FontWeight.w400, ), ), child: MyApp(), )

Two built-in presets are available:

PresetDescription
TwTextDefaults.tailwindSans()System sans-serif stack matching Tailwind’s default (used by TwConfig.standard())
TwTextDefaults.platformDefault()Flutter’s platform-native font with no explicit font family

Known limitations

The following features are parsed but not applied or have incomplete support:

  • Percent-based sizingw-[50%] is parsed but not applied. Use fractional syntax (w-1/2) instead.
  • Fractional translatetranslate-x-1/2 is not supported. Use pixel values.
  • Fractional basisbasis-1/2 is not supported. Use spacing scale values or explicit sizing.