Allow free zoom and pan in drawing mode

This commit is contained in:
2026-02-05 18:47:28 +01:00
parent d1b5cb54f4
commit d94e9eeb3d

View File

@@ -96,19 +96,33 @@ class _DrawingBoardState extends State<DrawingBoard> {
} }
// Drawing mode: wrap with InteractiveViewer for zoom/pan // Drawing mode: wrap with InteractiveViewer for zoom/pan
return Align( // Use LayoutBuilder to get available size and center content manually
alignment: widget.alignment, return LayoutBuilder(
child: InteractiveViewer( builder: (context, constraints) {
// Calculate padding to center the content
final horizontalPadding =
(constraints.maxWidth - widget.boardSize.width) / 2;
final verticalPadding =
(constraints.maxHeight - widget.boardSize.height) / 2;
return InteractiveViewer(
transformationController: _transformationController, transformationController: _transformationController,
minScale: widget.minScale, minScale: widget.minScale,
maxScale: widget.maxScale, maxScale: widget.maxScale,
boundaryMargin: EdgeInsets.zero, boundaryMargin: const EdgeInsets.all(double.infinity),
constrained: true, constrained: false,
panEnabled: !_isDrawing, panEnabled: !_isDrawing,
scaleEnabled: !_isDrawing, scaleEnabled: !_isDrawing,
child: Padding(
padding: EdgeInsets.only(
left: horizontalPadding > 0 ? horizontalPadding : 0,
top: verticalPadding > 0 ? verticalPadding : 0,
),
child: content, child: content,
), ),
); );
},
);
} }
/// Builds the drawing layer with gesture handling. /// Builds the drawing layer with gesture handling.