onPointerDown method

  1. @override
void onPointerDown(
  1. PointerDownEvent event
)
override

Used by the Listener callback to start drawing

Implementation

@override
void onPointerDown(PointerDownEvent event) {
  if (!value.supportedPointerKinds.contains(event.kind)) return;
  var s = value;

  // Are there already pointers on the screen?
  if (value.activePointerIds.isNotEmpty) {
    s = value.map(
      drawing: (s) =>
          // If the current line already contains something
          (s.activeLine != null && s.activeLine!.points.length > 2)
              ? _finishLineForState(s)
              : s.copyWith(
                  activeLine: null,
                ),
      erasing: (s) => s,
    );
  } else if (value is Drawing) {
    s = (value as Drawing).copyWith(
      pointerPosition: _getPointFromEvent(event),
      activeLine: SketchLine(
        points: [_getPointFromEvent(event)],
        color: (value as Drawing).selectedColor,
        width: value.selectedWidth / value.scaleFactor,
      ),
    );
  }
  temporaryValue = s.copyWith(
    activePointerIds: [...value.activePointerIds, event.pointer],
  );
}