built_path 0.1.0

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

Built Path

This library can help Flutter applications pre-compile SVG Path data into Flutter (dart:ui) Path objects.

For example:

import 'package:built_path_annotations/built_path_annotations.dart';

part 'example.svg_path.g.dart';

@SvgPath('M10 10 L20 20 Z')
Path get diagonalLine => _$diagonalLine;

Will generate Dart code like the following:

part of 'example.dart'

Path __$diagonalLine;
Path get _$diagonalLine => __$diagonalLine ??
  (__$diagonalLine = new Path()
                      ..moveTo(10.0, 10.0)
                      ..lineTo(20.0, 20.0)
                      ..close());

Note that for a Flutter project, you'll have to run flutter packages pub run build_runner build. Follow https://github.com/flutter/flutter/issues/13360, as this syntax may change in a future version of Flutter.

Also note that there will be an error reported about dart:ui until https://github.com/dart-lang/build/issues/733 is resolved, but the code should still get generated.

The example/ folder contains a full working example for Flutter, including the build.yaml and generated code.

CHANGELOG

0.1.0

  • First release

example/lib/main.dart

import 'dart:ui' show Path;

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

part 'main.svg_path.g.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: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  @SvgPath('M20,30 Q40,5 60,30 T100,30')
  // @SvgPath('M10 20 C 10 10 20 10 25 20 S 40 30 40 20')
  Path get path => _$MyHomePage_path;

  @SvgPath('M 250,75 L 323,301 131,161 369,161 177,301 z',
      fillRule: FillRule.evenOdd)
  Path get star => _$MyHomePage_star;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(title),
      ),
      body: new Column(
        children: <Widget>[
          new CustomPaint(painter: new PathPainter(path)),
          new CustomPaint(painter: new PathPainter(star, false)),
        ],
      ),
    );
  }
}

class PathPainter extends CustomPainter {
  PathPainter(this.path, [this.isStroke = true]);

  final Path path;
  final bool isStroke;

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawPath(
        path,
        new Paint()
          ..style = isStroke ? PaintingStyle.stroke : PaintingStyle.fill
          ..strokeWidth = 4.0);
  }

  @override
  bool shouldRepaint(PathPainter oldDelegate) => true;

  @override
  bool shouldRebuildSemantics(PathPainter oldDelegate) => false;
}

Use this package as a library

1. Depend on it

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


dependencies:
  built_path: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:built_path/built_path.dart';
  
Version Uploaded Documentation Archive
0.1.0 Aug 2, 2018 Go to the documentation of built_path 0.1.0 Download built_path 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
31
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: other

Primary library: package:built_path/built_path.dart with components: io, isolate, build, mirrors.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
analyzer ^0.32.0 0.32.6 0.33.0
build ^0.12.7 0.12.8 1.0.1
built_path_annotations ^0.1.0 0.1.0
path_parsing ^0.1.2 0.1.2
source_gen ^0.9.0 0.9.1+3
Transitive dependencies
args 1.5.0
async 2.0.8
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
csslib 0.14.6
dart_style 1.1.3 1.2.0
front_end 0.1.4+2 0.1.6
glob 1.1.7
html 0.13.3+3
kernel 0.3.4+2 0.3.6
logging 0.11.3+2
meta 1.1.6
package_config 1.0.5
path 1.6.2
plugin 0.2.0+3
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
utf 0.9.0+5
vector_math 2.0.8
watcher 0.9.7+10
yaml 2.1.15
Dev dependencies
build_config ^0.3.1
build_runner ^0.9.2
build_test ^0.10.3
test >=0.12.34 <1.0.0