Skip to content

Commit b8371f6

Browse files
committed
🧑‍💻 inherit handleAlignment from TransformableBox for AngularHandle.
1 parent c944a2f commit b8371f6

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/flutter_box_transform/lib/src/handles.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'dart:math';
33
import 'package:box_transform/box_transform.dart';
44
import 'package:flutter/material.dart';
55

6+
import 'transformable_box.dart';
7+
68
/// Default width of the border of the handles.
79
const kDefaultHandleBorderWidth = 1.5;
810

@@ -167,9 +169,6 @@ class AngularHandle extends StatelessWidget {
167169
/// Whether the handle has a shadow.
168170
final bool hasShadow;
169171

170-
/// The alignment of the handle.
171-
final HandleAlignment handleAlignment;
172-
173172
/// Creates a new angular corner handle.
174173
const AngularHandle({
175174
super.key,
@@ -178,11 +177,13 @@ class AngularHandle extends StatelessWidget {
178177
this.thickness = 5,
179178
this.color,
180179
this.hasShadow = true,
181-
this.handleAlignment = HandleAlignment.inside,
182180
});
183181

184182
@override
185183
Widget build(BuildContext context) {
184+
final handleAlignment =
185+
TransformableBox.widgetOf(context)?.handleAlignment ??
186+
HandleAlignment.outside;
186187
return LayoutBuilder(
187188
builder: (context, constraints) {
188189
return Container(

packages/flutter_box_transform/lib/src/transformable_box.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,18 @@ class TransformableBox extends StatefulWidget {
282282
constraints = constraints ?? const BoxConstraints.expand(),
283283
resizeModeResolver = resizeModeResolver ?? defaultResizeModeResolver;
284284

285+
/// Returns the [TransformableBox] of the closest ancestor.
286+
static TransformableBox? widgetOf(BuildContext context) {
287+
return context.findAncestorWidgetOfExactType<TransformableBox>();
288+
}
289+
290+
/// Returns the [TransformableBoxController] of the closest ancestor.
291+
static TransformableBoxController? controllerOf(BuildContext context) {
292+
return context
293+
.findAncestorStateOfType<_TransformableBoxState>()
294+
?.controller;
295+
}
296+
285297
@override
286298
State<TransformableBox> createState() => _TransformableBoxState();
287299
}

0 commit comments

Comments
 (0)