Skip to content

Commit 7ecbf89

Browse files
committed
🧑‍💻 add debugPaintHandleBounds param for painting handle bounds.
1 parent b8371f6 commit 7ecbf89

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

packages/flutter_box_transform/lib/src/handle_builders.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:box_transform/box_transform.dart';
2+
import 'package:flutter/foundation.dart';
23
import 'package:flutter/material.dart';
34

45
import 'typedefs.dart';
@@ -31,6 +32,9 @@ class CornerHandleWidget extends StatelessWidget {
3132
/// Whether the handle is resizable.
3233
final bool enabled;
3334

35+
/// Whether to paint the handle's bounds for debugging purposes.
36+
final bool debugPaintHandleBounds;
37+
3438
/// Creates a new handle widget.
3539
CornerHandleWidget({
3640
super.key,
@@ -42,6 +46,7 @@ class CornerHandleWidget extends StatelessWidget {
4246
this.onPanEnd,
4347
this.onPanCancel,
4448
required this.enabled,
49+
this.debugPaintHandleBounds = false,
4550
}) : assert(handlePosition.isDiagonal, 'A corner handle must be diagonal.');
4651

4752
@override
@@ -61,6 +66,13 @@ class CornerHandleWidget extends StatelessWidget {
6166
);
6267
}
6368

69+
if(kDebugMode && debugPaintHandleBounds) {
70+
child = ColoredBox(
71+
color: Colors.orange.withOpacity(0.5),
72+
child: child,
73+
);
74+
}
75+
6476
return Positioned(
6577
left: handlePosition.influencesLeft ? 0 : null,
6678
right: handlePosition.influencesRight ? 0 : null,
@@ -115,6 +127,9 @@ class SideHandleWidget extends StatelessWidget {
115127
/// Whether the handle is resizable.
116128
final bool enabled;
117129

130+
/// Whether to paint the handle's bounds for debugging purposes.
131+
final bool debugPaintHandleBounds;
132+
118133
/// Creates a new handle widget.
119134
SideHandleWidget({
120135
super.key,
@@ -126,6 +141,7 @@ class SideHandleWidget extends StatelessWidget {
126141
this.onPanEnd,
127142
this.onPanCancel,
128143
required this.enabled,
144+
this.debugPaintHandleBounds = false,
129145
}) : assert(handlePosition.isSide, 'A cardinal handle must be cardinal.');
130146

131147
@override
@@ -145,6 +161,13 @@ class SideHandleWidget extends StatelessWidget {
145161
);
146162
}
147163

164+
if(kDebugMode && debugPaintHandleBounds) {
165+
child = ColoredBox(
166+
color: Colors.yellow.withOpacity(0.5),
167+
child: child,
168+
);
169+
}
170+
148171
return Positioned(
149172
left: handlePosition.isVertical
150173
? handleTapSize

packages/flutter_box_transform/lib/src/transformable_box.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ class TransformableBox extends StatefulWidget {
219219
/// [onTerminalHeightReached] into one callback function.
220220
final TerminalEvent? onTerminalSizeReached;
221221

222+
/// Whether to paint the handle's bounds for debugging purposes.
223+
final bool debugPaintHandleBounds;
224+
222225
/// Creates a [TransformableBox] widget.
223226
const TransformableBox({
224227
super.key,
@@ -267,6 +270,7 @@ class TransformableBox extends StatefulWidget {
267270
this.onTerminalWidthReached,
268271
this.onTerminalHeightReached,
269272
this.onTerminalSizeReached,
273+
this.debugPaintHandleBounds = false,
270274
}) : assert(
271275
(controller == null) ||
272276
((rect == null) &&
@@ -568,6 +572,7 @@ class _TransformableBoxState extends State<TransformableBox> {
568572
key: ValueKey(handle),
569573
handlePosition: handle,
570574
handleTapSize: widget.handleTapSize,
575+
debugPaintHandleBounds: widget.debugPaintHandleBounds,
571576
enabled:
572577
widget.resizable && widget.enabledHandles.contains(handle),
573578
onPanStart: (event) => onHandlePanStart(event, handle),
@@ -582,6 +587,7 @@ class _TransformableBoxState extends State<TransformableBox> {
582587
key: ValueKey(handle),
583588
handlePosition: handle,
584589
handleTapSize: widget.handleTapSize,
590+
debugPaintHandleBounds: widget.debugPaintHandleBounds,
585591
enabled:
586592
widget.resizable && widget.enabledHandles.contains(handle),
587593
onPanStart: (event) => onHandlePanStart(event, handle),

packages/flutter_box_transform/playground/lib/main.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,13 +797,11 @@ class _ClampingRectState extends State<ClampingRect> {
797797
handle: handle,
798798
color: mainColor,
799799
hasShadow: false,
800-
handleAlignment: HandleAlignment.inside,
801800
),
802801
sideHandleBuilder: (context, handle) => AngularHandle(
803802
handle: handle,
804803
color: mainColor,
805804
hasShadow: false,
806-
handleAlignment: HandleAlignment.inside,
807805
),
808806
contentBuilder: (context, _, flip) => Container(
809807
width: model.clampingRect.width,

0 commit comments

Comments
 (0)