FLUTTER ECOSYSTEM

dnfield/flutter_path_drawing

dnfield/flutter_path_drawing open-source repository details.

flutter_path_drawing 프로젝트 이미지
Stars
170
Forks
32
최근 푸시(UTC)
2022. 11. 1.
프로젝트 상태
활성
Dan Field GitHub avatar
GITHUB User

Dan Field ↗

Software Engineer @google for @flutter

@google
언어Dart

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 7 개

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

path_drawing

pub package

A Flutter library to assist with creating and manipulating paths.

Currently supports parsing a Path from an SVG path data string (including normalizing the path commands to be amenable to Flutter's exposed Path methods).

Dash paths has an initial implementation that relies on flutter 0.3.6 at a minimum.

Planned for future release(s):

  • Trim paths

Example

Parse some path from svg string:

import 'package:path_drawing/path_drawing.dart';

final trianglePath = parseSvgPathData('M150 0 L75 200 L225 200 Z');

Create CustomPainter:

class FilledPathPainter extends CustomPainter {
  const FilledPathPainter({
    @required this.path,
    @required this.color,
  });

  final Path path;
  final Color color;

  @override
  bool shouldRepaint(FilledPathPainter oldDelegate) =>
      oldDelegate.path != path || oldDelegate.color != color;

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawPath(
      path,
      Paint()
        ..color = color
        ..style = PaintingStyle.fill,
    );
  }

  @override
  bool hitTest(Offset position) => path.contains(position);
}

Use it inside CustomPaint:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => print('tap'),
      child: CustomPaint(
        painter: FilledPathPainter(
          path: trianglePath,
          color: Colors.blue,
        ),
      ),
    );
  }
}

More examples can be found in example folder