패키지, 저장소 및 앱 카테고리 검색

draw_your_image 표지
패키지 상세v0.12.1

draw_your_image

사용자가 설계한 UI에서 손가락으로 그릴 수 있도록 해주는 플러터 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
528
좋아요
55
Pub 점수
160

패키지 설치

flutter pub add draw_your_image

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Draw_Your_Image는 사용자가 손가락이나 스타일러스로 사용자 정의된 UI 위에 직접 그릴 수 있도록 해주는 플러터 패키지입니다. 앱 내에서 스케치, 페인팅 또는 서명을 위한 간단하고 인터랙티브한 캔버스를 제공합니다. 창의적인 도구, 메모 앱, 디지털 서명 캡처에 적합하며 모바일, 웹, 데스크톱 등 다양한 플랫폼을 지원합니다. 플러터 위젯 시스템과 원활하게 통합되며 사용자 지정 브러시 설정도 제공합니다. 오픈소스이며 전담 개발자가 유지 관리하고 있습니다.

사용 사례

  • 디지털 스케치
  • 서명 캡처
  • 인터랙티브 화이트보드
  • 교육용 그림 그리기 앱
  • 창의적 디자인 도구

주요 기능

  • 터치 기반의 그림 그리기
  • 사용자 정의 가능한 브러시 크기 및 색상
  • 크로스 플랫폼 지원
  • Flutter와의 간단한 통합
  • 오픈소스 코드베이스

적합한 대상

  • 창의적인 도구를 구축하는 앱 개발자
  • 인터랙티브 학습 앱을 만드는 교육자
  • 사용자 서명이 필요한 앱
  • 그림 기능이 필요한 디자이너
  • 상호작용 인터페이스 프로토타이핑

고려 사항

  • 저사양 기기에서는 성능이 다를 수 있습니다
  • 제한된 고급 편집 도구
  • 내장된 내보내기 기능 없음
  • 수동으로 저장/로드 로직을 처리해야 합니다
  • 브러시 사용자 정의 옵션은 기본적입니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

draw_your_image

A Flutter package for creating customizable drawing canvases with a declarative API.

demo gif of draw_your_image

Core Concept

Fully declarative, fully customizable

  • No controllers required - Manage stroke data in your widget state
  • Customize everything - Control stroke behavior through simple callbacks
  • Bring your own features - Implement undo/redo, zoom/pan, image export as your app needs

This package focuses on providing a flexible drawing widget, leaving app-specific features to you.

Features

✨ Device-aware drawing - Distinguish between stylus, finger, and mouse input
🎨 Flexible stroke handling - Customize behavior per input device or any other criteria
🖌️ Built-in smoothing - Catmull-Rom spline interpolation included
⚙️ Fully customizable - Colors, widths, smoothing algorithms
🔍 Intersection detection - Customizable stroke overlap detection

Quick Start

class MyDrawingPage extends StatefulWidget {
  @override
  _MyDrawingPageState createState() => _MyDrawingPageState();
}

class _MyDrawingPageState extends State<MyDrawingPage> {
  /// Store all the strokes on app side as state
  List<Stroke> _strokes = [];

  @override
  Widget build(BuildContext context) {
    return Draw(
      strokes: _strokes, // pass strokes via 
      onStrokeDrawn: (stroke) {
        // store new drawn stroke and rebuild
        setState(() {
          _strokes = [..._strokes, stroke];
        });
      },
    );
  }
}

That's it! The canvas accepts any input and draws with default settings.

Device-Aware Drawing with onStrokeStarted

The onStrokeStarted callback lets you control stroke behavior based on input devices or any other criteria.

Stroke? Function(Stroke newStroke, Stroke? currentStroke)

Parameters:

  • newStroke - The stroke about to be started
  • currentStroke - The stroke currently being drawn (null if none)

Return:

  • The stroke to draw (can be newStroke, currentStroke, or a modified version)
  • null to reject the stroke
Example: Stylus draws, finger erases

If you want to draw lines with stylus while erase them with a finger, the function can be implemented like below:

extension on PointerDeviceKind {
  bool get isStylus =>
      this == PointerDeviceKind.stylus ||
      this == PointerDeviceKind.invertedStylus;
}

Draw(
  strokes: _strokes,
  onStrokeDrawn: (stroke) => setState(() => _strokes = [..._strokes, stroke]),
  onStrokeStarted: (newStroke, currentStroke) {
    if (currentStroke != null) return currentStroke;

    if (newStroke.deviceKind.isStylus) {
      // if stylus, draw black line
      return newStroke.copyWith(color: Colors.black);
    } else {
      // if finger, pixel eraser — tag with data so strokePainter can identify it
      return newStroke.copyWith(data: {#erasing: true}, width: 20.0);
    }
  },
  strokePainter: (stroke) =>
      stroke.data?[#erasing] == true
          ? [eraseWithDefault(stroke)]
          : [paintWithDefault(stroke)],
)
Example: Stylus-only drawing

If pre-defined utility functions fit to your needs, you can pick one of them.

Draw(
  strokes: _strokes,
  onStrokeDrawn: (stroke) => setState(() => _strokes.add(stroke)),
  onStrokeStarted: stylusOnlyHandler,  // Pre-defined utility
)
Pre-defined Utilities
  • stylusOnlyHandler - Accept only stylus input
  • stylusPriorHandler - Prioritize stylus when drawing (palm rejection)

API Reference

Draw Widget Properties
Property Type Required Description
strokes List<Stroke> ✓ List of strokes to display
onStrokeDrawn void Function(Stroke) ✓ Called when a stroke is complete
onStrokeStarted Stroke? Function(Stroke, Stroke?) Control stroke behavior based on input
onStrokeUpdated Stroke? Function(Stroke) Modify stroke in real-time as points are added
onStrokesSelected void Function(List<Stroke>) Called when strokes are selected
strokeColor Color Default stroke color
strokeWidth double Default stroke width
backgroundColor Color Canvas background color
pathBuilder Path Function(Stroke) Function to build Path from a Stroke. Use for smoothing or pressure-sensitive effects
strokePainter List<Paint> Function(Stroke) Custom stroke painting function
intersectionDetector IntersectionDetector Custom intersection detection function
shouldAbsorbScale bool Function(PointerDownEvent) Control whether to absorb scale/pan pointer events from parent widgets like InteractiveViewer
shouldAbsorbLongPress bool Function(PointerDownEvent) Control whether to absorb long press pointer events from parent widgets like GestureDetector
Stroke Properties
class Stroke {
  PointerDeviceKind deviceKind;     // Input device type
  List<StrokePoint> points;         // Stroke points with pressure/tilt data
  Color color;                      // Stroke color
  double width;                     // Stroke width
}
StrokePoint

Each point in a stroke contains rich input data:

class StrokePoint {
  final Offset position;       // Position of the point
  final double pressure;       // Raw pressure (0.0 to 1.0+)
  final double pressureMin;    // Minimum pressure for this device
  final double pressureMax;    // Maximum pressure for this device
  final double tilt;           // Stylus tilt angle (0 to π/2 radians)
  final double orientation;    // Stylus orientation (-π to π radians)
  
  // Normalized pressure getter (0.0 to 1.0)
  double get normalizedPressure;
}

Note that all the parameters are originated in Flutter's PointerEvent. See documentation of PointerEvent for detailed information.

Key features:

  • tilt and orientation enable calligraphy-style effects
  • normalizedPressure automatically adjusts for device-specific pressure ranges
  • Works seamlessly with all input devices (stylus, touch, mouse)

Path Builder Modes

Path building algorithm is also customizable. You can choose pre-defined modes below or provide your own Path Function(Stroke).

PathBuilderMode.catmullRom.converter        // Smooth curves (default)
PathBuilderMode.none.converter              // No smoothing (straight lines)
PathBuilderMode.pressureSensitive.converter // Variable-width based on pressure

Pressure-Sensitive Drawing

Create variable-width strokes that respond to stylus pressure using PathBuilderMode.pressureSensitive:

Draw(
  strokes: _strokes,
  strokeWidth: 8.0,
  pathBuilder: PathBuilderMode.pressureSensitive.converter,
  onStrokeDrawn: (stroke) => setState(() => _strokes.add(stroke)),
)
Tilt-Based Effects

For advanced calligraphy effects using stylus tilt and orientation:

Path calligraphyPath(Stroke stroke) {
  for (final point in stroke.points) {
    // More tilt (flat stylus) = wider stroke
    final tiltFactor = 1.0 + (point.tilt / (math.pi / 2)) * 1.5;
    final width = baseWidth * tiltFactor * point.normalizedPressure;
    
    // Use orientation to rotate brush angle
    final angle = point.orientation;
    // ... create path with rotated brush shape
  }
}

Draw(
  pathBuilder: calligraphyPath,
  // ...
)

See example/lib/pages/tilt_demo_page.dart for a complete implementation.

Custom Stroke Painting with strokePainter

The strokePainter callback allows you to fully customize how strokes are rendered. You can create advanced visual effects like gradients, glows, shadows, and shader effects by returning multiple Paint objects.

Draw(
  strokePainter: (Stroke stroke) {
    final List<Paint> paint = _buildYourPaint(stroke);
    return paint;
  },
)

Parameters:

  • stroke - The stroke to be painted

Return:

  • A list of Paint objects to be applied to the stroke (in order)
Example: Gradient Effect
LayoutBuilder(
  builder: (context, constraints) {
    final canvasSize = Size(constraints.maxWidth, constraints.maxHeight);

    return Draw(
      strokes: _strokes,
      onStrokeDrawn: (stroke) => setState(() => _strokes.add(stroke)),
      strokePainter: (stroke) {
        final gradient = ui.Gradient.linear(
          Offset.zero,
          Offset(canvasSize.width, canvasSize.height),
          [Colors.blue, Colors.purple, Colors.pink],
        );

        return [
          Paint()
            ..shader = gradient
            ..strokeWidth = stroke.width
            ..strokeCap = StrokeCap.round
            ..style = PaintingStyle.stroke,
        ];
      },
    );
  },
)
Example: Multi-Layer Effect (Glow)
strokePainter: (stroke) {
  return [
    // Outer glow
    paintWithOverride(stroke, strokeWidth: stroke.width + 8, strokeColor: Colors.cyan)
      ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 8),
    // Inner glow
    paintWithOverride(stroke, strokeWidth: stroke.width + 4, strokeColor: Colors.blue)
      ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 4),
    // Core stroke
    paintWithDefault(stroke),
  ];
}
Helper Functions

The package provides utility functions for creating Paint objects:

  • paintWithDefault - Creates a paint with default properties
  • paintWithOverride - Creates a paint with overridden properties
  • eraseWithDefault - Creates a paint with BlendMode.clear for pixel-level erasing

Using with InteractiveViewer

The shouldAbsorbScale callback allows you to control which pointer events are handled by the Draw widget versus parent widgets like InteractiveViewer. This enables powerful combinations like:

  • Touch for pan/zoom, stylus for drawing
  • Device-specific gesture handling
  • Conditional pointer event absorption
InteractiveViewer(
  child: Draw(
    strokes: _strokes,
    shouldAbsorbScale: (event) {
      // Absorb stylus events for drawing, let touch events pass through for pan/zoom
      return event.kind == PointerDeviceKind.stylus ||
             event.kind == PointerDeviceKind.invertedStylus;
    },
    onStrokeDrawn: (stroke) => setState(() => _strokes.add(stroke)),
    onStrokeStarted: (newStroke, currentStroke) {
      if (currentStroke != null) return currentStroke;
      // Only draw with stylus (touch is for pan/zoom)
      return newStroke.deviceKind == PointerDeviceKind.stylus ? newStroke : null;
    },
  ),
)

See the example app for a complete implementation of touch-for-pan/stylus-for-draw functionality.

Working with AI Assistants

This package is designed to work well with AI coding assistants. If you want accurate response from AI agents, refer AI_GUIDE.md before asking.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.