Skip to content

Commit

Permalink
🔧 Fix null resizeModeResolver pattern & Fix controller pattern not up…
Browse files Browse the repository at this point in the history
…dating the UI.
  • Loading branch information
SaadArdati committed Jun 1, 2023
1 parent 1bcdbb8 commit 4cbeb93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 6 additions & 8 deletions packages/flutter_box_transform/lib/src/transformable_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class TransformableBox extends StatefulWidget {

/// The callback function that is used to resolve the [ResizeMode] based on
/// the pressed keys on the keyboard.
final ValueGetter<ResizeMode>? resizeModeResolver;
final ValueGetter<ResizeMode> resizeModeResolver;

/// A callback that is called every time the [TransformableBox] is updated.
/// This is called every time the [TransformableBoxController] mutates the box
Expand Down Expand Up @@ -485,7 +485,6 @@ class _TransformableBoxState extends State<TransformableBox> {
final UIResizeResult result = controller.onResizeUpdate(
event.localPosition,
handle,
notify: false,
);

widget.onChanged?.call(result, event);
Expand Down Expand Up @@ -536,7 +535,6 @@ class _TransformableBoxState extends State<TransformableBox> {
void onDragPointerMove(PointerMoveEvent event) {
final UIMoveResult result = controller.onDragUpdate(
event.localPosition,
notify: false,
);

widget.onChanged?.call(result, event);
Expand All @@ -552,12 +550,12 @@ class _TransformableBoxState extends State<TransformableBox> {
@override
Widget build(BuildContext context) {
final Flip flip = controller.flip;
final Rect box = controller.rect;
final Rect rect = controller.rect;

Widget content = Transform.scale(
scaleX: widget.allowContentFlipping && flip.isHorizontal ? -1 : 1,
scaleY: widget.allowContentFlipping && flip.isVertical ? -1 : 1,
child: widget.contentBuilder(context, box, flip),
child: widget.contentBuilder(context, rect, flip),
);

if (controller.movable) {
Expand All @@ -572,16 +570,16 @@ class _TransformableBoxState extends State<TransformableBox> {
}

return Positioned.fromRect(
rect: box.inflate(widget.handleAlignment.offset(widget.handleTapSize)),
rect: rect.inflate(widget.handleAlignment.offset(widget.handleTapSize)),
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
Positioned(
left: widget.handleAlignment.offset(widget.handleTapSize),
top: widget.handleAlignment.offset(widget.handleTapSize),
width: box.width,
height: box.height,
width: rect.width,
height: rect.height,
child: content,
),
if (controller.resizable || !widget.hideHandlesWhenNotResizable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ class TransformableBoxController extends ChangeNotifier {
_constraints = constraints ?? const BoxConstraints(),
_resizable = resizable,
_movable = movable,
_resizeModeResolver = resizeModeResolver,
_resizeModeResolver = resizeModeResolver ?? defaultResizeModeResolver,
_allowFlippingWhileResizing = allowFlippingWhileResizing;

/// The callback function that is used to resolve the [ResizeMode] based on
/// the pressed keys on the keyboard.
ValueGetter<ResizeMode>? _resizeModeResolver;
ValueGetter<ResizeMode> _resizeModeResolver;

/// The callback function that is used to resolve the [ResizeMode] based on
/// the pressed keys on the keyboard.
ValueGetter<ResizeMode>? get resizeModeResolver => _resizeModeResolver;
ValueGetter<ResizeMode> get resizeModeResolver => _resizeModeResolver;

/// The current [Rect] of the [TransformableBox].
Rect _rect = Rect.zero;
Expand Down Expand Up @@ -136,8 +136,10 @@ class TransformableBoxController extends ChangeNotifier {
BoxConstraints get constraints => _constraints;

/// Sets the current [resizeModeResolver] of the [TransformableBox].
void setResizeModeResolver(ValueGetter<ResizeMode>? resizeModeResolver,
{bool notify = true}) {
void setResizeModeResolver(
ValueGetter<ResizeMode> resizeModeResolver, {
bool notify = true,
}) {
_resizeModeResolver = resizeModeResolver;

if (notify) notifyListeners();
Expand Down Expand Up @@ -292,7 +294,7 @@ class TransformableBoxController extends ChangeNotifier {
handle: handle,
initialRect: initialRect,
initialLocalPosition: initialLocalPosition,
resizeMode: resizeModeResolver!(),
resizeMode: resizeModeResolver(),
initialFlip: initialFlip,
clampingRect: clampingRect,
constraints: constraints,
Expand Down

0 comments on commit 4cbeb93

Please sign in to comment.