Getting Started
Installation
Add this package to your dependencies in your pubspec.yaml file:
dependencies:
box_transform: <latest_version>
Models
Box Transform defines several models to mimic that of Flutter's.
- The equivalent of
SizeisDimension. - The equivalent of
OffsetisVector2from thevector_mathpackage. - The equivalent of
RectisBox. - The equivalent of
BoxConstraintsisConstraints.
Usage
You can call the BoxTransformer.resize method to resize a box. The method takes the following parameters:
handle: The handle that is being dragged.
initialRect: The box before resizing started.
initialLocalPosition: The position of the mouse pointer before resizing started.
localPosition: The current position of the mouse pointer.
resizeMode: The resize mode. See Resize Modes for more information.
initialFlip: The flip state before resizing started.
Resizing a Box
final Box rect = Box.fromLTWH(50, 50, 100, 100);
final ResizeResult result = BoxTransformer.resize(
handle: HandlePosition.bottomRight, // handle that is being dragged
initialRect: rect,
initialLocalPosition: Vector2.zero(),
localPosition: Vector2.zero(),
resizeMode: ResizeMode.freeform,
initialFlip: Flip.none,
);
result.rect; // the new rect
You can also use a isolates for these simultaneous resizing operations since this is a pure dart implementation.
You can use BoxTransformer.move to move a box.
Moving a box
final Box rect = Box.fromLTWH(50, 50, 100, 100);
final MoveResult result = BoxTransformer.move(
initialRect: rect,
initialLocalPosition: Vector2.zero(),
localPosition: Vector2.zero(),
);
result.position; // the new position of the box

