apptomate_custom_sized_box 0.0.1

SDKflutter
Platformandroidioswindowslinuxmacosweb

An enhanced version of Flutter's `SizedBox` with additional sizing constraints, aspect ratio control, and debugging capabilities.

CustomSizedBox

An enhanced version of Flutter's SizedBox with additional sizing constraints, aspect ratio control, and debugging capabilities.

Features

  • All standard SizedBox functionality
  • Minimum and maximum size constraints
  • Aspect ratio enforcement
  • Visual debugging options
  • Runtime validation for negative dimensions
  • Demo showcasing various configurations

Installation

Add the dependency to your pubspec.yaml:

dependencies:
  apptomate_custom_sized_box: ^0.0.1

Usage

Basic Usage

CustomSizedBox(
  width: 200,
  height: 100,
  child: Container(color: Colors.blue),
)

Available Parameters

ParameterTypeDefaultDescription
widthdouble?nullExact width of the box
heightdouble?nullExact height of the box
minWidthdouble?nullMinimum width constraint
maxWidthdouble?nullMaximum width constraint
minHeightdouble?nullMinimum height constraint
maxHeightdouble?nullMaximum height constraint
aspectRatiodouble?nullWidth/height ratio (overrides width/height)
debugPaintboolfalseShows debug borders when true
debugColorColorColors.redColor for debug borders
childWidget?nullChild widget to contain

Advanced Examples

With aspect ratio:

CustomSizedBox(
  aspectRatio: 16/9,
  child: Image.network('https://example.com/image.jpg'),
)

With size constraints:

CustomSizedBox(
  minWidth: 100,
  maxWidth: 300,
  minHeight: 50,
  child: Container(color: Colors.green),
)

Debug mode:

CustomSizedBox(
  width: 150,
  height: 150,
  debugPaint: true,
  child: FlutterLogo(),
)

Demo

The package includes a CustomSizedBoxWidget demo that shows four different configurations:

  1. Basic SizedBox
  2. With aspect ratio (16:9)
  3. With size constraints (and debug paint)
  4. Empty SizedBox (spacer example)

To run the demo:

void main() {
  runApp(MaterialApp(
    home: CustomSizedBoxWidget(),
  ));
}

Implementation Details

The widget builds upon SizedBox with these additional layers:

  1. AspectRatio (when specified)
  2. ConstrainedBox (for min/max constraints)
  3. Debug Container (when debugPaint is true)

Validation Rules

The widget includes assertions to prevent invalid values:

  • Width and height cannot be negative
  • Aspect ratio must be positive

Comparison with Flutter's SizedBox

FeatureFlutter SizedBoxCustomSizedBox
Exact sizingYesYes
Aspect ratioNoYes
Size constraintsNoYes
Debug visualizationManualBuilt-in
ValidationNoYes

Best Practices

  1. Use aspectRatio for media containers (images, videos)
  2. Apply minWidth/minHeight for responsive layouts
  3. Enable debugPaint during development to visualize boxes
  4. Combine with other layout widgets for complex designs

Common Use Cases

  • Creating responsive containers
  • Enforcing aspect ratios for media
  • Building layout scaffolding
  • Debugging layout issues
  • Creating consistent spacing