Process SVG Path data into Flutter Path objects using build_runner.
Built Path #
This library can help Flutter applications pre-compile SVG Path data into
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
https://github.com/dart-lang/build/issues/733 is resolved, but the code should
still get generated.
example/ folder contains a full working example for Flutter, including
build.yaml and generated code.