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

Library for creating and managing a canvas similar to CustomPaint but with more features.

RePaint #

Pub Actions Status Coverage License: MIT Linter GitHub stars

Library for creating and managing a canvas similar to CustomPaint but with more features.

How to #

Handle mouse events #

@override
@mustCallSuper
void onPointerEvent(PointerEvent event) {
  case (event) {
    case PointerDownEvent e:
    case PointerUpEvent e:
    case PointerCancelEvent e:
    case PointerPanZoomStartEvent e:
    case PointerPanZoomUpdateEvent e:
    case PointerPanZoomEndEvent e:
    case PointerScrollEvent e:
    case PointerSignalEvent e:
    case PointerHoverEvent e:
      break;
    case PointerMoveEvent e:
      // Move the [_rect] by the [_offset] on mouse drag
      final rect = _rect.shift(_offset);
      if (!rect.contains(e.localPosition)) return;
      _offset += move.delta;
  }
}

Handle keyboard events #

To handle keyboard events you can use HardwareKeyboard manager:

bool _onKeyEvent(KeyEvent event) {
  if (event.deviceType != KeyEventDeviceType.keyboard) return false;
  if (event is! KeyDownEvent) return false;
  // F1 - do something
  switch (event.logicalKey) {
    case LogicalKeyboardKey.f1:
      doSomething();
      return true;
    default:
      return false;
  }
}

@override
void mount(_, __) {
  HardwareKeyboard.instance.addHandler(_onKeyEvent);
}

@override
void unmount() {
  HardwareKeyboard.instance.removeHandler(_onKeyEvent);
}

or wrap RePaint with Focus widget and use onKeyEvent to handle keyboard events:

final painter = RePainterImpl();

Widget build(BuildContext context) {
  return Focus(
    onKeyEvent: painter.onKeyEvent,
    child: RePaint(
      painter: painter,
    ),
  );
}
12
likes
160
points
289
downloads

Publisher

verified publisherplugfox.dev

Weekly Downloads

Library for creating and managing a canvas similar to CustomPaint but with more features.

Repository (GitHub)
View/report issues
Contributing

Topics

#paint #painter #game #shader #custom

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com
www.patreon.com
boosty.to

License

MIT (license)

Dependencies

flutter, meta

More

Packages that depend on repaint