Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions built_path/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ Path get _$diagonalLine => __$diagonalLine ??
```

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.
`dart run build_runner build`.

The `example/` folder contains a full working example for Flutter, including
the `build.yaml` and generated code.
the `build.yaml` and generated code.
4 changes: 2 additions & 2 deletions built_path/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class MyApp extends StatelessWidget {
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

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

@SvgPath('M20,30 Q40,5 60,30 T100,30')
Expand Down
4 changes: 2 additions & 2 deletions built_path/example/lib/main.svg_path.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions built_path/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: A new Flutter project.
version: 1.0.0+1

environment:
sdk: '>=2.0.0-dev <3.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
built_path:
Expand All @@ -22,7 +22,7 @@ dependencies:

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
cupertino_icons: ^1.0.5

dev_dependencies:
build_runner: ^2.1.4
Expand Down
9 changes: 3 additions & 6 deletions built_path/lib/src/flutter_path_proxy.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import 'package:path_parsing/path_parsing.dart';

class FlutterPathGenProxy extends PathProxy {
FlutterPathGenProxy() {
code = new StringBuffer();
code.write('new Path()');
}

StringBuffer code;
StringBuffer code =
StringBuffer()
..write('new Path()');

@override
void close() {
Expand Down
27 changes: 19 additions & 8 deletions built_path/lib/src/path_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:built_path_annotations/built_path_annotations.dart';
import 'package:path_parsing/path_parsing.dart';
import 'package:source_gen/source_gen.dart';

Builder svgPathSharedPartBuilder({String formatOutput(String code)}) {
Builder svgPathSharedPartBuilder({String formatOutput(String code)?}) {
return new PartBuilder(
<Generator>[new SvgPathGenerator()], '.svg_path.g.dart',
formatOutput: formatOutput,
Expand All @@ -29,23 +29,26 @@ class SvgPathGenerator extends Generator {
}

void checkField(Element field, StringBuffer buffer, String friendlyName) {
DartObject annotation = _checker.firstAnnotationOf(field);
DartObject? annotation = _checker.firstAnnotationOf(field);
if (annotation == null && field is FieldElement) {
annotation = _checker.firstAnnotationOf(field.getter);
final PropertyAccessorElement? getter = field.getter;
if (getter != null) {
annotation = _checker.firstAnnotationOf(getter);
}
}
if (annotation != null) {
buffer.writeln('Path __\$$friendlyName;');
buffer.writeln('Path? __\$$friendlyName;');
buffer.writeln(
'Path get _\$$friendlyName => __\$$friendlyName ?? (__\$$friendlyName =');
final FlutterPathGenProxy proxy = new FlutterPathGenProxy();

writeSvgPathDataToPath(
annotation.getField('data').toStringValue(),
annotation.getField('data')?.toStringValue(),
proxy,
);
buffer.write(proxy);

final int fillRuleIndex =
final int? fillRuleIndex =
annotation.getField('fillRule')?.getField('index')?.toIntValue();
if (fillRuleIndex != null) {
buffer.write(_getFillRule(fillRuleIndex));
Expand All @@ -58,12 +61,20 @@ class SvgPathGenerator extends Generator {
FutureOr<String> generate(LibraryReader library, BuildStep buildStep) async {
final StringBuffer buffer = new StringBuffer();
for (Element el in library.allElements) {
final String? name = el.name;
if (name == null) {
continue;
}
if (el is ClassElement) {
for (FieldElement field in el.fields) {
checkField(field, buffer, '${el.name}_${field.name}');
final String? fieldName = field.name;
if (fieldName == null) {
continue;
}
checkField(field, buffer, '${name}_$fieldName');
}
} else {
checkField(el, buffer, el.name);
checkField(el, buffer, name);
}
}
return buffer.toString();
Expand Down
4 changes: 2 additions & 2 deletions built_path/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ author: Dan Field <dfield@gmail.com>
homepage: https://github.com/dnfield/flutter_built_path

environment:
sdk: '>=2.0.0-dev <3.0.0'
sdk: '>=3.0.0 <4.0.0'
# flutter: ">=0.5.1 <2.0.0"

dependencies:
analyzer: ^2.7.0
analyzer: ^5.13.0
build: ^2.1.1
built_path_annotations: ^0.1.0
# built_path_annotations:
Expand Down
6 changes: 3 additions & 3 deletions built_path/test/src/simple_example.svg_path.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion built_path_annotations/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ author: Dan Field <dfield@gmail.com>
homepage: https://github.com/dnfield/flutter_built_path

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=3.0.0 <4.0.0'
# flutter: ">=0.5.1 <2.0.0"

# dependencies:
Expand Down