path_drawing 0.2.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new78

path_drawing

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

CHANGELOG

  • 0.2.3: Fix bugs in _decomposeCubic - Offset.scale and Offset.translate related

  • 0.2.2: Fix handling of null dashOffset

  • 0.2.1: Add support for dashed paths, update docs

  • 0.2.0: not published

  • 0.1.1: Fix bug in matrix translate logic

  • 0.1.0: Initial release

example/main.dart

import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:path_drawing/path_drawing.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[new CustomPaint(painter: new PathTestPainter())],
        ),
      ),
    );
  }
}

class PathTestPainter extends CustomPainter {
  final Path p = parseSvgPathData(
      '''M19.0281,19.40466 20.7195,19.40466 20.7195,15.71439 24.11486,15.71439 24.11486,14.36762 20.7195,14.36762 
20.7195,11.68641 24.74134,11.68641 24.74134,10.34618 19.0281,10.34618 	z''');
  final Path p5 = parseSvgPathData(
      '''M 15 15.5 A 0.5 1.5 0 1 1  14,15.5 A 0.5 1.5 0 1 1  15 15.5 z''');
  final Path p2 = new Path()
    ..moveTo(10.0, 10.0)
    ..lineTo(100.0, 100.0)
    //..lineTo(125.0, 20.0)
    ..quadraticBezierTo(125.0, 20.0, 200.0, 100.0)
    ..addRect(new Rect.fromLTWH(0.0, 0.0, 50.0, 50.0));
  final Path p3 = new Path()
    ..addRect(new Rect.fromLTWH(20.0, 20.0, 50.0, 50.0));
  final Paint black = new Paint()
    ..color = Colors.black
    ..strokeWidth = 1.0
    ..style = PaintingStyle.stroke;
  final Paint red = new Paint()
    ..color = Colors.red
    ..strokeWidth = 5.0
    ..style = PaintingStyle.stroke;

  @override
  bool shouldRepaint(PathTestPainter old) => true;

  static Float64List matrix(
      double a, double b, double c, double d, double e, double f) {
    return new Matrix4(
            a, b, 0.0, 0.0, c, d, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, e, f, 0.0, 1.0)
        .storage;
  }

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawPath(
        p5.transform(matrix(0.866, 0.5, -0.5, 0.866, 9.693, -5.173)), red);
    canvas.drawPath(p2, black);
    canvas.translate(0.0, -100.0);
    canvas.drawPath(
        dashPath(p2,
            dashArray: new CircularIntervalList<double>(
                <double>[5.0, 10.0, 15.0, 15.0]),
            dashOffset: new DashOffset.percentage(.05)),
        red);
    canvas
      ..scale(5.0, 5.0)
      ..translate(-50.0, -35.0);
    canvas.drawPath(p3, red);
    canvas.drawPath(p2, red);
    canvas.drawPath(Path.combine(PathOperation.intersect, p2, p3), black);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  path_drawing: "^0.2.3"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:path_drawing/path_drawing.dart';
  
Version Uploaded Documentation Archive
0.2.3 May 14, 2018 Go to the documentation of path_drawing 0.2.3 Download path_drawing 0.2.3 archive
0.2.2 May 9, 2018 Go to the documentation of path_drawing 0.2.2 Download path_drawing 0.2.2 archive
0.2.1 May 8, 2018 Go to the documentation of path_drawing 0.2.1 Download path_drawing 0.2.1 archive
0.1.1 Apr 26, 2018 Go to the documentation of path_drawing 0.1.1 Download path_drawing 0.1.1 archive
0.1.0 Apr 26, 2018 Go to the documentation of path_drawing 0.1.0 Download path_drawing 0.1.0 archive

Analysis

We analyzed this package on May 22, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.54.0
  • pana: 0.11.1
  • Flutter: 0.4.4

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
57 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
78
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run flutter format to format lib/path_drawing.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
meta >=1.1.2 <2.0.0 1.1.5
vector_math >=2.0.6 <3.0.0 2.0.6 2.0.7
Transitive dependencies
collection 1.14.6 1.14.9
sky_engine 0.0.99
typed_data 1.1.5
Dev dependencies
flutter_test
test >=0.12.34 <1.0.0