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

FlexBox

FlexBox combines Flutter’s Container and Flex widgets with Mix styling.

It provides both box styling (decoration, padding, margins, transforms, constraints) and flex layout capabilities (direction, alignment, spacing) in a single widget. This makes it ideal for creating styled flex layouts without nesting multiple widgets.

For specific layouts, use RowBox for horizontal layouts or ColumnBox for vertical layouts.

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

final style = FlexBoxStyler() .direction(Axis.horizontal) .mainAxisAlignment(MainAxisAlignment.spaceBetween) .crossAxisAlignment(CrossAxisAlignment.center) .padding(16) .spacing(12) .color(Colors.grey.shade100) .borderRounded(8); FlexBox( style: style, children: [ StyledIcon(icon: Icons.star), StyledText('Rating'), StyledText('4.5'), ], )

Constructor

PropTypeRequired / Default Value
styleStyleconst FlexBoxStyler.create()
styleSpecStyleSpec?Optional
childrenList<Widget>const <Widget>[]

Style API Reference

FlexBox Methods

MethodDescription
animateSets the animation property.
alignmentSets the alignment property.
transformAlignmentSets the transform alignment.
clipBehaviorSets the clip behavior.
gapSets gap value (deprecated).
modifierSets the widget modifier.
foregroundDecorationSets the foreground decoration.
flexSets the flex property.
paddingSets the padding property.
marginSets the margin property.
transformSets the transform property.
decorationSets the decoration property.
constraintsSets the constraints property.
wrapSets the widget modifier (wrap).
variantsSets the variants list.
borderRadiusSets the border radius property via decoration.
borderSets the border property via decoration.

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

Flex

MethodDescription
directionSets flex direction
mainAxisAlignmentSets main axis alignment
crossAxisAlignmentSets cross axis alignment
mainAxisSizeSets main axis size
verticalDirectionSets vertical direction
textDirectionSets text direction
textBaselineSets text baseline
spacingSets spacing
rowConvenience method for setting direction to horizontal (row)
columnConvenience method for setting direction to vertical (column)

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)