Intermediate
FittedBox: Fitting Content into a Box Without Overflow
· 6 min read

What Is FittedBox?
In Flutter, a widget that is bigger than the space given to it overflows. In debug mode you see the yellow-and-black striped "RenderFlex overflowed" warning; in release mode the content gets cut off or spills out. Prices, statistic values, usernames and button labels with long translations are especially prone to this.
FittedBox first lays out its child at its natural size without constraints, then scales and positions it within its own space according to the fit parameter. The scaling works like a Transform. The font size doesn't change; the whole painting is scaled up or down.

Basic Usage
SizedBox(
width: 120,
height: 48,
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(Icons.star, color: Colors.amber),
SizedBox(width: 8),
Text(
'1.250.000',
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
),
],
),
),
)The Row that doesn't fit into the 120-pixel box is scaled down proportionally thanks to FittedBox. With alignment: Alignment.centerLeft, the shrunken content is aligned to the left instead of being centered.
BoxFit Options
The fit parameter determines how the child is placed into the FittedBox's space. In the image below, a 120x180 portrait content is placed into a 160x110 landscape frame with each BoxFit value:

• fill: Fills the frame completely, ignoring the aspect ratio. The content may be distorted. • contain: Fits the entire content into the frame while preserving the aspect ratio. There may be empty space. This is the default for FittedBox. • cover: Covers the frame completely while preserving the aspect ratio. Overflowing parts are clipped. • fitWidth: Matches the width exactly and calculates the height from the ratio. • fitHeight: Matches the height exactly and calculates the width from the ratio. • none: Doesn't scale at all and positions the content according to alignment. • scaleDown: Shrinks the content like contain if it doesn't fit, and leaves it untouched if it does. Never enlarges.
Why scaleDown Most of the Time?
The default value, contain, doesn't just shrink content; it also enlarges it when there is room. A small label placed in a wide area can suddenly become huge. For text, the desired behavior is usually "shrink if it doesn't fit, leave it as is if it does", so scaleDown is the safest choice. That is why the content stays at its natural size in the 260-pixel box in the image.
Other Parameters
• alignment: The position of the scaled content within the FittedBox. Defaults to Alignment.center. • clipBehavior: Defaults to Clip.none. Use Clip.hardEdge to clip the content for values that can overflow, such as cover and none.
Things to Watch Out For
1. The FittedBox Itself Must Be Bounded
FittedBox scales its content according to its own space. If the parent gives it unbounded space (for example, inside a Row without Expanded), the FittedBox grows as large as its content and no scaling happens:
// No effect: Row gives FittedBox unbounded width
Row(
children: [
FittedBox(child: Text(longTitle)),
],
)
// Correct: Expanded bounds the width
Row(
children: [
Expanded(
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Text(longTitle),
),
),
],
)2. The Child Is Laid Out Unconstrained
FittedBox gives its child unbounded constraints. That is why a Text inside it doesn't wrap and stays on a single line. If you put in a Row that uses Expanded, or a widget that tries to grow infinitely like a ListView, you get a layout error. The child must have a natural size of its own.
3. Don't Forget Accessibility
Because FittedBox visually shrinks text, it can also shrink the text of a user who prefers a large font size. For critical and long texts, maxLines with overflow: TextOverflow.ellipsis or line wrapping may be more appropriate. FittedBox is best used for short, single-line values.
4. Image.fit Is Enough for Images
The Image widget already has a fit parameter. You don't need to wrap an image in a FittedBox to fit it into a frame. FittedBox makes sense for widgets that don't have their own fit option.
A Real Example: A Responsive Stat Card
On dashboard screens, the same card is used both on a wide tablet screen and on a narrow phone screen. The value might be "42" or "$1,250,000". With FittedBox, the card looks right in every case:
class StatCard extends StatelessWidget {
const StatCard({super.key, required this.label, required this.value});
final String label;
final String value;
@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
return Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: textTheme.labelMedium),
const SizedBox(height: 8),
FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Text(value, style: textTheme.headlineLarge),
),
],
),
),
);
}
}Because the Column uses crossAxisAlignment: start, the FittedBox gets an upper bound equal to the card's width. If the value fits, it stays at headlineLarge size; if not, it shrinks only as much as needed.
Conclusion
FittedBox is a practical tool that solves overflow problems with a single wrapper. Use it with fit: BoxFit.scaleDown for text and icon combinations, make sure the FittedBox itself is bounded, and keep accessibility in mind for long texts.