bounding_box 0.0.4 copy "bounding_box: ^0.0.4" to clipboard
bounding_box: ^0.0.4 copied to clipboard

Flutter widget that allows you to drag, resize, and rotate.

Flutter BoundingBox Widget #

enter image description here

The BoundingBox is a custom Flutter widget that allows you to drag, resize, and rotate any widget with a bounding box overlay. It's useful for building design tools, image editors, diagram creators, and other interactive visual UIs.


โœจ Features #

  • Move (drag) any widget freely on the screen.
  • Resize from 8 handles (top, bottom, sides, and corners).
  • Rotate via a draggable rotate handle.
  • Customizable handle appearance, stroke color, stroke width, etc.
  • Optional custom widgets for resize and rotate handles.
  • Optionally disable the interactive functionality.

๐Ÿงฉ Constructor Parameters #

BoundingBox({
  required Widget Function(Size size, Offset position, double rotation) builder,
  required Offset initialPosition,
  required Size initialSize,
  double? initialRotation,
  bool enable = true,
  double? handleResizeSize,
  double? handleRotateSize,
  Color? handleResizeBackgroundColor,
  Color? handleResizeStrokeColor,
  Color? handleRotateBackgroundColor,
  Color? handleRotateStrokeColor,
  Color? strokeColor,
  double? strokeWidth,
  double? handleResizeStrokeWidth,
  double? handleRotateStrokeWidth,
  Widget? rotateIcon,
  Widget? customHandleResize,
  Widget? customHandleRotate,
  double? handleRotatePosition,
  BoxDecoration? customDecoration,
})

๐Ÿ“Œ Required #

  • builder: A function that takes the current Size, Position, Rotation and returns a widget.

  • initialPosition: Starting position of the bounding box.

  • initialSize: Starting size of the widget.


๐Ÿงช Example Usage #

import 'package:bounding_box/bounding_box.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter BoundingBox Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: BoundingBox(
        initialSize: const Size(150, 150),
        initialPosition: const Offset(150, 200),
        builder: (size, position, rotation) {
          return Container(
            width: size.width,
            height: size.height,
            color: Colors.orange,
            alignment: Alignment.center,
            child: const Text("Drag / Resize / Rotate"),
          );
        },
      ),
    );
  }
}

๐Ÿ“ Visual Handle Layout #

Handles are placed in 8 positions:

topLeft      topCenter      topRight

centerLeft                 centerRight

bottomLeft  bottomCenter  bottomRight 

A rotate handle is positioned above topCenter.


๐Ÿšซ Disabling Interactions #

You can disable all interactions using:

enable: false

This will render only the widget without any interactive overlay.


๐Ÿง  Final Thoughts #

This BoundingBox widget offers a lightweight and extensible way to add draggable, resizable, and rotatable components in Flutter, perfect for design apps, whiteboard tools, diagramming editors, and more.

4
likes
160
points
24
downloads

Publisher

verified publishersaddamnur.xyz

Weekly Downloads

Flutter widget that allows you to drag, resize, and rotate.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on bounding_box