Skip to content

Commit 3410d04

Browse files
SaadArdatiBirjuVachhani
authored andcommitted
🪄 Refactor API.
1 parent 7ed90b4 commit 3410d04

File tree

5 files changed

+428
-358
lines changed

5 files changed

+428
-358
lines changed

packages/flutter_box_transform/example/lib/main.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ class _ImageBoxState extends State<ImageBox> {
723723
flip: box.flip,
724724
clampingRect: model.clampingEnabled ? model.clampingRect : null,
725725
constraints: box.constraintsEnabled ? box.constraints : null,
726-
onChanged: (result) {
726+
onChangeUpdate: (result, event) {
727727
widget.onChanged?.call(result);
728728
largestClampingBox = result.largestRect;
729729
setState(() {});
@@ -735,24 +735,23 @@ class _ImageBoxState extends State<ImageBox> {
735735
!widget.selected || box.hideHandlesWhenNotResizable,
736736
movable: widget.selected && box.movable,
737737
allowContentFlipping: box.flipChild,
738-
flipWhileResizing: box.flipRectWhileResizing,
739-
allowResizeOverflow: false,
740-
onResizeStart: (event) {
738+
allowFlippingWhileResizing: box.flipRectWhileResizing,
739+
onResizeStart: (handle, event) {
741740
if (!showTestRecorder || !recorder.isRecording) return;
742741

743742
log('Recording resize action');
744743
currentAction = recorder.onAction(
745744
resizeMode: currentResizeMode,
746745
flip: box.flip,
747746
rect: box.rect,
748-
handle: event.handle,
747+
handle: handle,
749748
cursorPosition: event.localPosition,
750749
clampingRect: model.clampingEnabled ? model.clampingRect : null,
751750
constraints: box.constraintsEnabled ? box.constraints : null,
752751
flipRect: box.flipRectWhileResizing,
753752
);
754753
},
755-
onResizeEnd: (event) {
754+
onResizeEnd: (handle, event) {
756755
if (!showTestRecorder ||
757756
currentAction == null ||
758757
!recorder.isRecording ||
@@ -771,6 +770,7 @@ class _ImageBoxState extends State<ImageBox> {
771770
bool reachedMaxWidth,
772771
bool reachedMinHeight,
773772
bool reachedMaxHeight,
773+
event,
774774
) {
775775
if (minWidthReached == reachedMinWidth &&
776776
minHeightReached == reachedMinHeight &&
@@ -909,12 +909,13 @@ class _ClampingRectState extends State<ClampingRect> {
909909
flip: Flip.none,
910910
clampingRect: model.playgroundArea!,
911911
constraints: BoxConstraints(minWidth: minWidth, minHeight: minHeight),
912-
onChanged: (result) => model.setClampingRect(result.rect),
912+
onChangeUpdate: (result, event) => model.setClampingRect(result.rect),
913913
onTerminalSizeReached: (
914914
bool reachedMinWidth,
915915
bool reachedMaxWidth,
916916
bool reachedMinHeight,
917917
bool reachedMaxHeight,
918+
event,
918919
) {
919920
if (minWidthReached == reachedMinWidth &&
920921
minHeightReached == reachedMinHeight &&
@@ -928,18 +929,18 @@ class _ClampingRectState extends State<ClampingRect> {
928929
maxHeightReached = reachedMaxHeight;
929930
});
930931
},
931-
handleAlign: HandleAlign.inside,
932+
handleAlignment: HandleAlignment.inside,
932933
cornerHandleBuilder: (context, handle) => AngularHandle(
933934
handle: handle,
934935
color: mainColor,
935936
hasShadow: false,
936-
handleAlign: HandleAlign.inside,
937+
handleAlign: HandleAlignment.inside,
937938
),
938939
sideHandleBuilder: (context, handle) => AngularHandle(
939940
handle: handle,
940941
color: mainColor,
941942
hasShadow: false,
942-
handleAlign: HandleAlign.inside,
943+
handleAlign: HandleAlignment.inside,
943944
),
944945
contentBuilder: (context, _, flip) => Container(
945946
width: model.clampingRect.width,

packages/flutter_box_transform/lib/src/handle.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import '../flutter_box_transform.dart';
88
const kDefaultHandleBorderWidth = 1.5;
99

1010
/// Alignment of the handle.
11-
enum HandleAlign {
11+
enum HandleAlignment {
1212
/// The handle is completely inside the box corner/side.
1313
inside,
1414

@@ -20,22 +20,22 @@ enum HandleAlign {
2020
center;
2121

2222
/// Whether handle align is inside or not.
23-
bool get isInside => this == HandleAlign.inside;
23+
bool get isInside => this == HandleAlignment.inside;
2424

2525
/// Whether handle align is outside or not.
26-
bool get isOutside => this == HandleAlign.outside;
26+
bool get isOutside => this == HandleAlignment.outside;
2727

2828
/// Whether handle align is center or not.
29-
bool get isCenter => this == HandleAlign.center;
29+
bool get isCenter => this == HandleAlignment.center;
3030

3131
/// Returns offset of the handle from the box corner/side.
3232
double offset(double handleSize) {
3333
switch (this) {
34-
case HandleAlign.inside:
34+
case HandleAlignment.inside:
3535
return 0;
36-
case HandleAlign.outside:
36+
case HandleAlignment.outside:
3737
return handleSize;
38-
case HandleAlign.center:
38+
case HandleAlignment.center:
3939
return handleSize / 2;
4040
}
4141
}
@@ -169,7 +169,7 @@ class AngularHandle extends StatelessWidget {
169169
final bool hasShadow;
170170

171171
/// The alignment of the handle.
172-
final HandleAlign handleAlign;
172+
final HandleAlignment handleAlign;
173173

174174
/// Creates a new angular corner handle.
175175
const AngularHandle({
@@ -179,7 +179,7 @@ class AngularHandle extends StatelessWidget {
179179
this.thickness = 5,
180180
this.color,
181181
this.hasShadow = true,
182-
this.handleAlign = HandleAlign.inside,
182+
this.handleAlign = HandleAlignment.inside,
183183
});
184184

185185
@override
@@ -236,7 +236,7 @@ class AngularHandlePainter extends CustomPainter {
236236
final Paint shadowPaint;
237237

238238
/// The alignment of the handle.
239-
final HandleAlign handleAlign;
239+
final HandleAlignment handleAlign;
240240

241241
/// Creates a new handle painter.
242242
AngularHandlePainter({
@@ -245,7 +245,7 @@ class AngularHandlePainter extends CustomPainter {
245245
required this.handle,
246246
this.length = 32,
247247
this.hasShadow = true,
248-
this.handleAlign = HandleAlign.inside,
248+
this.handleAlign = HandleAlignment.inside,
249249
}) : strokePaint = Paint()
250250
..color = color
251251
..strokeWidth = thickness
@@ -319,7 +319,7 @@ class AngularHandlePainter extends CustomPainter {
319319
Offset getCenter(
320320
Size size,
321321
HandlePosition handle,
322-
HandleAlign handleAlign,
322+
HandleAlignment handleAlign,
323323
double thickness,
324324
) {
325325
final multiplier = handleAlign.isInside

0 commit comments

Comments
 (0)