apptomate_custom_positioned 0.0.1
apptomate_custom_positioned: ^0.0.1 copied to clipboard
A reusable Flutter widget that wraps the standard `Positioned` widget with additional documentation and validation.
CustomPositioned #
A reusable Flutter widget that wraps the standard Positioned widget with additional documentation and validation.
Features #
- Provides a clean, documented interface for positioning widgets in a
Stack - Includes runtime validation to prevent common positioning mistakes
- Supports all standard
Positionedparameters (left,top,right,bottom,width,height) - Includes a demo widget showcasing different positioning examples
Installation #
Add the dependency to your pubspec.yaml:
dependencies:
apptomate_custom_positioned: ^0.0.1
Usage #
Basic Usage #
Stack(
children: [
// Background content...
CustomPositioned(
left: 20,
top: 20,
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
],
)
Available Parameters #
| Parameter | Type | Description |
|---|---|---|
left |
double | Distance from left edge |
top |
double | Distance from top edge |
right |
double | Distance from right edge |
bottom |
double | Distance from bottom edge |
width |
double | Child width (mutually exclusive with left/right) |
height |
double | Child height (mutually exclusive with top/bottom) |
child |
Widget | The widget to position (required) |
Validation Rules #
The widget includes assertions to prevent invalid combinations:
- Cannot specify both
widthandleft/right - Cannot specify both
heightandtop/bottom
Demo #
The package includes a CustomPositionedWidget demo that shows three positioned boxes:
- Top-left positioned (red)
- Bottom-right positioned (green)
- Center positioned (purple)
To run the demo:
void main() {
runApp(MaterialApp(
home: CustomPositionedWidget(),
));
}
Best Practices #
- Prefer using
width/heightORleft/right/top/bottombut not both - For centered positioning, calculate positions relative to parent size using
LayoutBuilder - Use the helper method
_buildPositionedBoxas a template for consistent positioned widgets