BoxFitWidgetExtensions extension
Extension methods for Widget that provide convenient box fitting functionality.
This extension adds methods to easily wrap widgets in FittedBox widgets with various fitting strategies. All methods return new FittedBox widgets without modifying the original widget.
FittedBox scales and positions its child within itself according to the specified BoxFit strategy. This is particularly useful for ensuring widgets fit properly within constrained spaces while maintaining their aspect ratio or filling the space.
Box Fit Strategies:
- contain: Scale to fit entirely within the box (may leave empty space)
- cover: Scale to fill the entire box (may crop content)
- fill: Stretch to fill the box exactly (may distort aspect ratio)
- fitWidth: Scale to fit the width exactly (may crop height)
- fitHeight: Scale to fit the height exactly (may crop width)
- scaleDown: Scale down only if needed (never scale up)
Example usage:
Icon(Icons.star, size: 100)
.fitContain() // Scales icon to fit within available space
.sizedBox(width: 50, height: 50);
- on
Methods
-
fitContain(
{AlignmentGeometry alignment = Alignment.center, Clip clipBehavior = Clip.none}) → FittedBox -
Available on Widget, provided by the BoxFitWidgetExtensions extension
Wraps the widget in a FittedBox with BoxFit.contain strategy. -
fitCover(
{AlignmentGeometry alignment = Alignment.center, Clip clipBehavior = Clip.none}) → FittedBox -
Available on Widget, provided by the BoxFitWidgetExtensions extension
Wraps the widget in a FittedBox with BoxFit.cover strategy. -
fitFill(
{AlignmentGeometry alignment = Alignment.center, Clip clipBehavior = Clip.none}) → FittedBox -
Available on Widget, provided by the BoxFitWidgetExtensions extension
Wraps the widget in a FittedBox with BoxFit.fill strategy. -
fitHeight(
{AlignmentGeometry alignment = Alignment.center, Clip clipBehavior = Clip.none}) → FittedBox -
Available on Widget, provided by the BoxFitWidgetExtensions extension
Wraps the widget in a FittedBox with BoxFit.fitHeight strategy. -
fitScaleDown(
{AlignmentGeometry alignment = Alignment.center, Clip clipBehavior = Clip.none}) → FittedBox -
Available on Widget, provided by the BoxFitWidgetExtensions extension
Wraps the widget in a FittedBox with BoxFit.scaleDown strategy. -
fittedBox(
{BoxFit fit = BoxFit.contain, AlignmentGeometry alignment = Alignment.center, Clip clipBehavior = Clip.none}) → FittedBox -
Available on Widget, provided by the BoxFitWidgetExtensions extension
Wraps the widget in a FittedBox with the specified fitting strategy.