├── doc └── svg_to_paint_logo.png ├── lib └── svg_to_paint.dart ├── test └── svg_to_paint_test.dart ├── CHANGELOG.md ├── LICENSE ├── pubspec.yaml ├── bin └── svg_to_paint.dart ├── example └── example.md ├── pubspec.lock └── README.md /doc/svg_to_paint_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrancescoCatani/svg_to_paint_dart/HEAD/doc/svg_to_paint_logo.png -------------------------------------------------------------------------------- /lib/svg_to_paint.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() => runApp(MyApp()); 4 | 5 | class MyApp extends StatelessWidget { 6 | // This widget is the root of your application. 7 | @override 8 | Widget build(BuildContext context) { 9 | return MaterialApp( 10 | title: 'Flutter Demo', 11 | theme: ThemeData( 12 | primarySwatch: Colors.blue, 13 | ), 14 | home: null, 15 | ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/svg_to_paint_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | import 'package:crypto/crypto.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | void main() { 7 | group('Test on file', () { 8 | test('Check if file has been created ', () async { 9 | await Process.run( 10 | 'flutter', 11 | [ 12 | 'pub', 13 | 'run', 14 | 'svg_to_paint', 15 | '/Users/user/Desktop/google_icon.xml', 16 | '/Users/user/Desktop', 17 | 'icon', 18 | 'absolute' 19 | ], 20 | runInShell: true); 21 | 22 | expect( 23 | File('/Users/user/Desktop/icon.dart').existsSync(), true); 24 | }); 25 | 26 | test('Check with MD5 hash', () { 27 | expect( 28 | md5.convert(utf8.encode(File('/Users/user/Desktop/icon.dart').readAsStringSync())).toString(), 29 | '3e13645991eb27fa8abb17e6abd240dc'); 30 | }); 31 | }); 32 | } 33 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.0.0] - First release. 2 | 3 | * First release of the package. 4 | 5 | ## [1.0.1] - First release. 6 | 7 | * First release of the package. 8 | 9 | ## [1.0.2] - First release. 10 | 11 | * First release of the package. 12 | 13 | ## [1.0.3] - First release. 14 | 15 | * First release of the package. 16 | 17 | ## [1.0.4] - First release. 18 | 19 | * First release of the package. 20 | 21 | ## [1.0.5] - First release. 22 | 23 | * First release of the package. 24 | 25 | ## [1.0.6] - Second release. 26 | 27 | * Improvements and test implementation. 28 | 29 | ## [1.0.7] - Second release. 30 | 31 | * Improvements, test implementation and example file. 32 | 33 | ## [1.0.8] - Third release. 34 | 35 | * Null Safety Support. 36 | 37 | ## [1.0.9+2] - Updating Md. 38 | 39 | * Md update. 40 | 41 | ## [1.0.9+3] - Updating Md. 42 | 43 | * Md update. 44 | 45 | ## [1.0.9+4] - Updating Md. 46 | 47 | * Md update. 48 | 49 | ## [1.0.9+5] - Updating Md. 50 | 51 | * Md update. 52 | 53 | # 1.0.8-nullsafety.0 54 | 55 | * Null Safety Support 56 | 57 | # 1.0.9-nullsafety.0 58 | 59 | * Null Safety Support 60 | 61 | # 1.0.10-dev.1 62 | 63 | * Updating markdown file -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Francesco Catani, Camillo Bucciarelli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: svg_to_paint 2 | description: svg_to_paint generates dart code from a svg file. Given an xml file you can draw its simply by typing a command. 3 | version: 1.0.9+5 4 | homepage: https://github.com/FrancescoCatani/svg_to_paint_dart 5 | 6 | environment: 7 | sdk: ">=2.12.0 <3.0.0" 8 | flutter: ">=1.16.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | path: ^1.6.4 14 | crypto: ^3.0.0 15 | 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | 20 | executables: 21 | svg_to_paint: 22 | 23 | # For information on the generic Dart part of this file, see the 24 | # following page: https://dart.dev/tools/pub/pubspec 25 | 26 | # The following section is specific to Flutter. 27 | flutter: 28 | 29 | # To add assets to your package, add an assets section, like this: 30 | # assets: 31 | # - images/a_dot_burr.jpeg 32 | # - images/a_dot_ham.jpeg 33 | # 34 | # For details regarding assets in packages, see 35 | # https://flutter.dev/assets-and-images/#from-packages 36 | # 37 | # An image asset can refer to one or more resolution-specific "variants", see 38 | # https://flutter.dev/assets-and-images/#resolution-aware. 39 | 40 | # To add custom fonts to your package, add a fonts section here, 41 | # in this "flutter" section. Each entry in this list should have a 42 | # "family" key with the font family name, and a "fonts" key with a 43 | # list giving the asset and other descriptors for the font. For 44 | # example: 45 | # fonts: 46 | # - family: Schyler 47 | # fonts: 48 | # - asset: fonts/Schyler-Regular.ttf 49 | # - asset: fonts/Schyler-Italic.ttf 50 | # style: italic 51 | # - family: Trajan Pro 52 | # fonts: 53 | # - asset: fonts/TrajanPro.ttf 54 | # - asset: fonts/TrajanPro_Bold.ttf 55 | # weight: 700 56 | # 57 | # For details regarding fonts in packages, see 58 | # https://flutter.dev/custom-fonts/#from-packages 59 | -------------------------------------------------------------------------------- /bin/svg_to_paint.dart: -------------------------------------------------------------------------------- 1 | library paint_to_svg; 2 | 3 | import 'dart:io' show Directory, File, Process; 4 | import 'dart:async'; 5 | import 'package:path/path.dart' as path; 6 | 7 | /// USAGE: 8 | /// 9 | /// COMMAND: 10 | /// svg_to_paint source_file destination_file file_name command 11 | /// 12 | /// EXAMPLE: 13 | /// svg_to_paint /Users/user/Desktop/file.xml /Users/user/Desktop svg_icon absolute 14 | /// 15 | /// DESCRIPTION: 16 | /// source_file: IS THE PATH OF YOUR XML FILE, FOR EXAMPLE (/Users/user/Desktop/file.xml) 17 | /// 18 | /// destination_file: IS THE DESTINATION PATH OF YOUR GENERATED DART FILE, FOR EXAMPLE (/Users/user/Desktop) 19 | /// 20 | /// file_name: IS THE NAME OF YOUR FILE, FOR EXAMPLE (svg_icon) 21 | /// command: THE command REPRESENTS THE SVG COORDINATES WHICH COULD BE 'absolute' or 'relative'. 22 | /// YOU CAN CHOOSE THEM TYPING: 23 | /// absolute IF YOU WANT ABSOLUTE COORDINATES 24 | /// relative IF YOU WANT RELATIVE COORDINATES 25 | 26 | Future main(List args) async { 27 | final nodeCode = "const svgToPaint = require('svg_to_paint')\n" + 28 | "svgToPaint.generateDartCode('${args[0]}','${args[1]}','${args[2]}','${args[3]}')"; 29 | 30 | final nodeCheckResult = 31 | await Process.run('node', ['--version'], runInShell: true); 32 | 33 | if (nodeCheckResult.exitCode != 0) { 34 | print('Please install Node.JS. Recommended v10+'); 35 | } 36 | 37 | await new Directory('dir').create(recursive: true).then((value) async { 38 | await Process.run( 39 | 'npm', 40 | ['install', 'svg_to_paint'], 41 | workingDirectory: value.path, 42 | runInShell: true, 43 | ).then((value) => print("Modules installed...")); 44 | 45 | await File(path.join(value.path, 'index.js')) 46 | .writeAsString(nodeCode) 47 | .then((file) async { 48 | print("Files Generated..."); 49 | 50 | await Process.run( 51 | 'node', 52 | ['index.js'], 53 | workingDirectory: value.path, 54 | runInShell: true, 55 | ).then((process) { 56 | print("Files Created..."); 57 | Directory("dir").deleteSync(recursive: true); 58 | }); 59 | }); 60 | }); 61 | } 62 | -------------------------------------------------------------------------------- /example/example.md: -------------------------------------------------------------------------------- 1 | # svg_to_paint 2 | 3 | svg_to_paint generates dart code from a svg file. This package is an abstraction of NodeJs package svg_to_paint. 4 | 5 | ## Requirements 6 | 7 | Node.JS v10+ 8 | 9 | ## Install: 10 | 11 | ```bash 12 | $ pub global activate svg_to_paint 13 | ``` 14 | 15 | ## Usage 16 | 17 | 1) Convert your xml svg in vector drawable (for example in https://svg2vector.com). 18 | 19 | 2) Type in terminal: 20 | 21 | ```bash 22 | svg_to_paint source_file_path destination_path name_file command 23 | ``` 24 | 25 | ## Params: 26 | 27 | \* - required 28 | 29 | - `source_file_path` * - is the path of your file, for example (/Users/user/Desktop/file.xml) 30 | 31 | - `destination_path` * - is the destination path of your dart generated files, for example (/Users/user/Desktop) 32 | 33 | - `name_file` * - is the name of your file, for example (icon) 34 | 35 | - `command` * - represents the coordinates type of svg. You can choose be absolute or relative. 36 | 37 | ## Example 38 | 39 | Given the svg file icon.xml in the folder named test, we will generate dart files in the same folder. 40 | 41 | ```bash 42 | svg_to_paint /User/dev/test/icon.xml /User/dev/test icon absolute 43 | ``` 44 | 45 | Generates: 46 | ``` 47 | dev 48 | └───test 49 | │ │ auto_painter.dart 50 | │ │ icon_generated.dart 51 | ``` 52 | 53 | Generated icon_generated.dart: 54 | 55 | ```dart 56 | // GENERATED CODE - DO NOT MODIFY BY HAND 57 | 58 | import 'auto_painter.dart'; 59 | 60 | class IconGenerated extends CustomPainter { 61 | 62 | final viewPortWidth = 24; 63 | final viewPortHeight = 24; 64 | 65 | String path0 = 'M,23.4,12.3,C,23.4,11.5,23.299999999999997,10.700000000000001,23.2,9.9,H,12,V,14.5,H,18.4,C,18.099999999999998,16,17.299999999999997,17.3,15.999999999999998,18.1,V,21.1,H,19.799999999999997,C,22.1,19,23.4,15.9,23.4,12.3,Z'; 66 | String path1 = 'M,12,24,C,15.2,24,17.9,22.9,19.9,21.1,L,16.099999999999998,18.1,C,14.999999999999998,18.8,13.599999999999998,19.200000000000003,11.999999999999998,19.200000000000003,C,8.899999999999999,19.200000000000003,6.199999999999998,17.1,5.299999999999998,14.300000000000002,H,1.299999999999998,V,17.400000000000002,C,3.3,21.4,7.5,24,12,24,Z'; 67 | String path2 = 'M,5.3,14.3,C,4.8,12.8,4.8,11.200000000000001,5.3,9.700000000000001,V,6.6,H,1.2999999999999998,C,-0.40000000000000013,10,-0.40000000000000013,14,1.2999999999999998,17.299999999999997,L,5.3,14.3,Z'; 68 | String path3 = 'M,12,4.8,C,13.7,4.8,15.3,5.3999999999999995,16.6,6.6,L,16.6,6.6,L,20,3.2,C,17.8,1.2000000000000002,15,0.10000000000000009,12,0.10000000000000009,C,7.5,0,3.3,2.6,1.3,6.6,L,5.3,9.7,C,6.2,6.9,8.9,4.8,12,4.8,Z'; 69 | 70 | @override 71 | void paint(Canvas canvas, Size size) { 72 | canvas.drawRect(Rect.fromLTRB(0, 0, size.width, size.height), 73 | Paint()..color = Color(0xFFffffff)); 74 | 75 | canvas.drawPath(drawPath(path0, viewPortWidth, viewPortHeight, size), Paint()..color = Color(0xFF4285F4)); 76 | canvas.drawPath(drawPath(path1, viewPortWidth, viewPortHeight, size), Paint()..color = Color(0xFF34A853)); 77 | canvas.drawPath(drawPath(path2, viewPortWidth, viewPortHeight, size), Paint()..color = Color(0xFFFBBC04)); 78 | canvas.drawPath(drawPath(path3, viewPortWidth, viewPortHeight, size), Paint()..color = Color(0xFFEA4335)); 79 | } 80 | 81 | @override 82 | bool shouldRepaint(CustomPainter oldDelegate) => false; 83 | 84 | } 85 | 86 | ``` 87 | 88 | and auto_painter.dart which will contains the methods to draw 89 | 90 | ## Contributing 91 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 92 | 93 | Please make sure to update tests as appropriate. 94 | 95 | ## License 96 | [MIT](https://choosealicense.com/licenses/mit/) 97 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.5.0" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "2.1.0" 18 | characters: 19 | dependency: transitive 20 | description: 21 | name: characters 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "1.1.0" 25 | charcode: 26 | dependency: transitive 27 | description: 28 | name: charcode 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "1.2.0" 32 | clock: 33 | dependency: transitive 34 | description: 35 | name: clock 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.15.0" 46 | crypto: 47 | dependency: "direct main" 48 | description: 49 | name: crypto 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "3.0.0" 53 | fake_async: 54 | dependency: transitive 55 | description: 56 | name: fake_async 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.2.0" 60 | flutter: 61 | dependency: "direct main" 62 | description: flutter 63 | source: sdk 64 | version: "0.0.0" 65 | flutter_test: 66 | dependency: "direct dev" 67 | description: flutter 68 | source: sdk 69 | version: "0.0.0" 70 | matcher: 71 | dependency: transitive 72 | description: 73 | name: matcher 74 | url: "https://pub.dartlang.org" 75 | source: hosted 76 | version: "0.12.10" 77 | meta: 78 | dependency: transitive 79 | description: 80 | name: meta 81 | url: "https://pub.dartlang.org" 82 | source: hosted 83 | version: "1.3.0" 84 | path: 85 | dependency: "direct main" 86 | description: 87 | name: path 88 | url: "https://pub.dartlang.org" 89 | source: hosted 90 | version: "1.8.0" 91 | sky_engine: 92 | dependency: transitive 93 | description: flutter 94 | source: sdk 95 | version: "0.0.99" 96 | source_span: 97 | dependency: transitive 98 | description: 99 | name: source_span 100 | url: "https://pub.dartlang.org" 101 | source: hosted 102 | version: "1.8.0" 103 | stack_trace: 104 | dependency: transitive 105 | description: 106 | name: stack_trace 107 | url: "https://pub.dartlang.org" 108 | source: hosted 109 | version: "1.10.0" 110 | stream_channel: 111 | dependency: transitive 112 | description: 113 | name: stream_channel 114 | url: "https://pub.dartlang.org" 115 | source: hosted 116 | version: "2.1.0" 117 | string_scanner: 118 | dependency: transitive 119 | description: 120 | name: string_scanner 121 | url: "https://pub.dartlang.org" 122 | source: hosted 123 | version: "1.1.0" 124 | term_glyph: 125 | dependency: transitive 126 | description: 127 | name: term_glyph 128 | url: "https://pub.dartlang.org" 129 | source: hosted 130 | version: "1.2.0" 131 | test_api: 132 | dependency: transitive 133 | description: 134 | name: test_api 135 | url: "https://pub.dartlang.org" 136 | source: hosted 137 | version: "0.2.19" 138 | typed_data: 139 | dependency: transitive 140 | description: 141 | name: typed_data 142 | url: "https://pub.dartlang.org" 143 | source: hosted 144 | version: "1.3.0" 145 | vector_math: 146 | dependency: transitive 147 | description: 148 | name: vector_math 149 | url: "https://pub.dartlang.org" 150 | source: hosted 151 | version: "2.1.0" 152 | sdks: 153 | dart: ">=2.12.0-0.0 <3.0.0" 154 | flutter: ">=1.16.0" 155 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Flutter Svg to Paint Package 3 |

4 | 5 |

6 | Pub 7 | Flutter Website 8 | NodeJs Website 9 | Star on Github 10 | License: MIT 11 |

12 | 13 | --- 14 | 15 | svg_to_paint generates dart code from a svg file. This package is an abstraction of NodeJs package svg_to_paint. 16 | 17 | --- 18 | 19 | ## Requirements 20 | 21 | Node.JS v10+ 22 | 23 | ## Install 24 | 25 | ```bash 26 | $ flutter pub global activate svg_to_paint 27 | ``` 28 | 29 | ## Usage 30 | 31 | 1) Convert your xml svg in vector drawable (for example in https://svg2vector.com) 32 | 33 | 2) Type in terminal: 34 | 35 | ```bash 36 | svg_to_paint source_file_path destination_path name_file command 37 | ``` 38 | 39 | ## Params 40 | 41 | \* - required 42 | 43 | - `source_file_path` * - is the path of your file, for example (/Users/user/Desktop/file.xml) 44 | 45 | - `destination_path` * - is the destination path of your dart generated files, for example (/Users/user/Desktop) 46 | 47 | - `name_file` * - is the name of your file, for example (icon) 48 | 49 | - `command` * - represents the coordinates type of svg. You can choose absolute or relative. 50 | 51 | ## Example 52 | 53 | Given the svg file icon.xml in the folder named test, we will generate dart files in the same folder. 54 | 55 | ```bash 56 | svg_to_paint /User/dev/test/icon.xml /User/dev/test icon absolute 57 | ``` 58 | 59 | Generates: 60 | ``` 61 | dev 62 | └───test 63 | │ │ auto_painter.dart 64 | │ │ icon_generated.dart 65 | ``` 66 | 67 | Generated icon_generated.dart: 68 | 69 | ```dart 70 | // GENERATED CODE 71 | 72 | import 'auto_painter.dart'; 73 | 74 | class IconGenerated extends CustomPainter { 75 | 76 | final viewPortWidth = 24; 77 | final viewPortHeight = 24; 78 | 79 | String path0 = 'M,23.4,12.3,C,23.4,11.5,23.299999999999997,10.700000000000001,23.2,9.9,H,12,V,14.5,H,18.4,C,18.099999999999998,16,17.299999999999997,17.3,15.999999999999998,18.1,V,21.1,H,19.799999999999997,C,22.1,19,23.4,15.9,23.4,12.3,Z'; 80 | String path1 = 'M,12,24,C,15.2,24,17.9,22.9,19.9,21.1,L,16.099999999999998,18.1,C,14.999999999999998,18.8,13.599999999999998,19.200000000000003,11.999999999999998,19.200000000000003,C,8.899999999999999,19.200000000000003,6.199999999999998,17.1,5.299999999999998,14.300000000000002,H,1.299999999999998,V,17.400000000000002,C,3.3,21.4,7.5,24,12,24,Z'; 81 | String path2 = 'M,5.3,14.3,C,4.8,12.8,4.8,11.200000000000001,5.3,9.700000000000001,V,6.6,H,1.2999999999999998,C,-0.40000000000000013,10,-0.40000000000000013,14,1.2999999999999998,17.299999999999997,L,5.3,14.3,Z'; 82 | String path3 = 'M,12,4.8,C,13.7,4.8,15.3,5.3999999999999995,16.6,6.6,L,16.6,6.6,L,20,3.2,C,17.8,1.2000000000000002,15,0.10000000000000009,12,0.10000000000000009,C,7.5,0,3.3,2.6,1.3,6.6,L,5.3,9.7,C,6.2,6.9,8.9,4.8,12,4.8,Z'; 83 | 84 | @override 85 | void paint(Canvas canvas, Size size) { 86 | canvas.drawRect(Rect.fromLTRB(0, 0, size.width, size.height), 87 | Paint()..color = Color(0xFFffffff)); 88 | 89 | canvas.drawPath(drawPath(path0, viewPortWidth, viewPortHeight, size), Paint()..color = Color(0xFF4285F4)); 90 | canvas.drawPath(drawPath(path1, viewPortWidth, viewPortHeight, size), Paint()..color = Color(0xFF34A853)); 91 | canvas.drawPath(drawPath(path2, viewPortWidth, viewPortHeight, size), Paint()..color = Color(0xFFFBBC04)); 92 | canvas.drawPath(drawPath(path3, viewPortWidth, viewPortHeight, size), Paint()..color = Color(0xFFEA4335)); 93 | } 94 | 95 | @override 96 | bool shouldRepaint(CustomPainter oldDelegate) => false; 97 | 98 | } 99 | 100 | ``` 101 | 102 | and auto_painter.dart which will contains the methods to draw 103 | 104 | ## Contributing 105 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 106 | 107 | Please make sure to update tests as appropriate. 108 | 109 | ## License 110 | [MIT](https://choosealicense.com/licenses/mit/) 111 | --------------------------------------------------------------------------------