MovablePoint class

A draggable point that can be moved around the coordinate system.

This widget displays an interactive point that users can drag to change its position. The point features smooth animations on hover and drag, matching the original Mafs library's design.

Features

  • Draggable with smooth visual feedback
  • Hover animations (point grows, ring expands)
  • Optional movement constraints (horizontal, vertical, or custom)

Example

class MyWidget extends StatefulWidget {
  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  Offset _point = const Offset(1, 1);

  @override
  Widget build(BuildContext context) {
    return Mafs(
      children: [
        MovablePoint(
          point: _point,
          onMove: (newPoint) => setState(() => _point = newPoint),
        ),
      ],
    );
  }
}

Constraints

You can constrain movement to an axis or custom path:

// Horizontal only
MovablePoint(
  point: point,
  onMove: onMove,
  constrain: MovablePoint.horizontal(point.dy),
)

// Vertical only
MovablePoint(
  point: point,
  onMove: onMove,
  constrain: MovablePoint.vertical(point.dx),
)

// Snap to grid
MovablePoint(
  point: point,
  onMove: onMove,
  constrain: (p) => Offset(p.dx.roundToDouble(), p.dy.roundToDouble()),
)
Inheritance

Constructors

MovablePoint({Key? key, required Offset point, required ValueChanged<Offset> onMove, ConstraintFunction? constrain, Color? color})
Creates a movable point.
const

Properties

color → Color?
The color of the point.
final
constrain → ConstraintFunction?
Optional function to constrain the point's movement.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onMove → ValueChanged<Offset>
Called when the user drags the point to a new position.
final
point → Offset
The current position of the point in math coordinates.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<MovablePoint>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

horizontal(double y) → ConstraintFunction
Creates a constraint function for horizontal movement only.
vertical(double x) → ConstraintFunction
Creates a constraint function for vertical movement only.