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

Box

Box is equivalent to Flutter’s Container, it provides styling capabilities through the Mix framework. It can be used to create visually styled boxes with decoration, padding, margins, transforms, and constraints.

You can use BoxStyler to create styles with a fluent API. Example:

final style = BoxStyler() .width(200) .height(100) .color(Colors.blue) .borderRounded(12) .padding(16); Box(style: style, child: Text('Hello Mix'))

Constructor

PropTypeRequired / Default Value
styleStyleconst BoxStyler.create()
styleSpecStyleSpec?Optional
childWidget?Optional

Style API Reference

Box Methods

MethodDescription
clipBehaviorSets the clip behavior.
alignmentSets the alignment.
modifierSets the widget modifier.
foregroundDecorationSets the foreground decoration.
transformSets the transform and optionally the alignment.
constraintsSets the box constraints.
paddingSets the padding.
marginSets the margin.
decorationSets the decoration.
animateSets the animation configuration.
wrapWraps with a widget modifier.
borderRadiusSets the border radius.
borderSets the border decoration.
variantsSets the style variants.

Animation

MethodDescription
keyframeAnimationCreates a keyframe animation. It will animate through the given timeline.
phaseAnimationCreates a phase animation. It will animate through the given phases.

Border Radius

MethodDescription
borderRadiusAllSets border radius for all corners.
borderRadiusTopSets border radius for the top corners.
borderRadiusBottomSets border radius for the bottom corners.
borderRadiusLeftSets border radius for the left corners.
borderRadiusRightSets border radius for the right corners.
borderRadiusTopLeftSets border radius for the top left corner.
borderRadiusTopRightSets border radius for the top right corner.
borderRadiusBottomLeftSets border radius for the bottom left corner.
borderRadiusBottomRightSets border radius for the bottom right corner.
borderRadiusTopStartSets border radius for the top start corner (directional).
borderRadiusTopEndSets border radius for the top end corner (directional).
borderRadiusBottomStartSets border radius for the bottom start corner (directional).
borderRadiusBottomEndSets border radius for the bottom end corner (directional).
borderRoundedSets a uniform circular radius for all corners.
borderRoundedTopSets a circular radius for the top corners.
borderRoundedBottomSets a circular radius for the bottom corners.
borderRoundedLeftSets a circular radius for the left corners.
borderRoundedRightSets a circular radius for the right corners.
borderRoundedTopLeftSets a circular radius for the top left corner.
borderRoundedTopRightSets a circular radius for the top right corner.
borderRoundedBottomLeftSets a circular radius for the bottom left corner.
borderRoundedBottomRightSets a circular radius for the bottom right corner.
borderRoundedTopStartSets a circular radius for the top start corner (directional).
borderRoundedTopEndSets a circular radius for the top end corner (directional).
borderRoundedBottomStartSets a circular radius for the bottom start corner (directional).
borderRoundedBottomEndSets a circular radius for the bottom end corner (directional).

Border

MethodDescription
borderTopSets the top border.
borderBottomSets the bottom border.
borderLeftSets the left border.
borderRightSets the right border.
borderStartSets the start border (RTL-aware).
borderEndSets the end border (RTL-aware).
borderVerticalSets vertical borders (top & bottom).
borderHorizontalSets horizontal borders (left & right).
borderAllSets all borders.

Constraint

MethodDescription
widthSets both min and max width to create a fixed width
heightSets both min and max height to create a fixed height
minWidthSets minimum width constraint
maxWidthSets maximum width constraint
minHeightSets minimum height constraint
maxHeightSets maximum height constraint
sizeSets both width and height to specific values
constraintsOnlyCreates constraints with only specified values, supporting priority resolution

Decoration

MethodDescription
colorSets background color
gradientSets gradient with any GradientMix type
shadowSets single shadow
shadowsSets multiple shadows
elevationSets elevation shadow
imageSets image decoration
shapeSets box shape
shapeCircleSets a circular shape (CircleBorder)
shapeStadiumSets a stadium shape (StadiumBorder)
shapeRoundedRectangleSets a rounded rectangle shape (RoundedRectangleBorder)
shapeBeveledRectangleSets a beveled rectangle shape (BeveledRectangleBorder)
shapeContinuousRectangleSets a continuous rectangle shape (ContinuousRectangleBorder)
shapeStarSets a star shape (StarBorder)
shapeLinearSets a linear border shape (LinearBorder)
shapeSuperellipseSets a superellipse shape (RoundedSuperellipseBorder)
backgroundImageSets a background image from an ImageProvider
backgroundImageUrlSets a background image from a network URL
backgroundImageAssetSets a background image from an asset path
foregroundLinearGradientSets a foreground linear gradient
foregroundRadialGradientSets a foreground radial gradient
foregroundSweepGradientSets a foreground sweep gradient
linearGradientSets a background linear gradient
radialGradientSets a background radial gradient
sweepGradientSets a background sweep gradient

Shadow

MethodDescription
shadowOnlyCreates a single box shadow with named parameters
boxShadowsCreates multiple box shadows from a list of BoxShadowMix
boxElevationCreates box shadows from Material Design elevation level

Spacing

MethodDescription
paddingTopSets the top padding.
paddingBottomSets the bottom padding.
paddingLeftSets the left padding.
paddingRightSets the right padding.
paddingXSets horizontal (left and right) padding.
paddingYSets vertical (top and bottom) padding.
paddingAllSets padding on all sides.
paddingStartSets the start (leading) padding.
paddingEndSets the end (trailing) padding.
paddingOnlySets custom padding for each side with priority resolution.
marginTopSets the top margin.
marginBottomSets the bottom margin.
marginLeftSets the left margin.
marginRightSets the right margin.
marginXSets horizontal (left and right) margin.
marginYSets vertical (top and bottom) margin.
marginAllSets margin on all sides.
marginStartSets the start (leading) margin.
marginEndSets the end (trailing) margin.
marginOnlySets custom margin for each side with priority resolution.

Transform

MethodDescription
rotateSets rotation transform
scaleSets scale transform
translateSets translation transform
skewSets skew transform
transformResetResets transform to identity (no effect)

Variant

MethodDescription
variantAdds a single variant to this style.
onDarkCreates a variant for dark mode.
onNotCreates a variant for when the context does NOT match the provided variant.
onLightCreates a variant for light mode.
onBuilderCreates a variant using a builder function that receives the build context.
builderDeprecated: Use [onBuilder] instead.
onBreakpointCreates a variant based on the specified breakpoint.
onPortraitCreates a variant for portrait device orientation.
onLandscapeCreates a variant for landscape device orientation.
onMobileCreates a variant for mobile breakpoint.
onTabletCreates a variant for tablet breakpoint.
onDesktopCreates a variant for desktop breakpoint.
onLtrCreates a variant for left-to-right text direction.
onRtlCreates a variant for right-to-left text direction.
onIosCreates a variant for iOS platform.
onAndroidCreates a variant for Android platform.
onMacosCreates a variant for macOS platform.
onWindowsCreates a variant for Windows platform.
onLinuxCreates a variant for Linux platform.
onFuchsiaCreates a variant for Fuchsia platform.
onWebCreates a variant for web platform.

Widget State Variant

MethodDescription
onHoveredCreates a variant for hover state
onPressedCreates a variant for pressed state
onFocusedCreates a variant for focused state
onDisabledCreates a variant for disabled state
onEnabledCreates a variant for enabled state (opposite of disabled)