From 1299114486146f29a5b494edea776557a5513d20 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 20:38:11 +0100 Subject: [PATCH 1/9] [example] add offline svg as example --- example/assets/3d_modeling | 1 + 1 file changed, 1 insertion(+) create mode 100644 example/assets/3d_modeling diff --git a/example/assets/3d_modeling b/example/assets/3d_modeling new file mode 100644 index 0000000..8711d98 --- /dev/null +++ b/example/assets/3d_modeling @@ -0,0 +1 @@ +3d modeling \ No newline at end of file From d6d51dd32f07b9c2dc8bc3f861aa51b8888b3132 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 20:39:59 +0100 Subject: [PATCH 2/9] [example] specify assets folder at pubspec.yaml --- example/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a0b4d84..12f2d50 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -43,8 +43,8 @@ flutter: uses-material-design: true # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg + assets: + - assets/ # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see From 5c0f955af0744302b5fd33f2fe340f0d0e9a3d42 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 20:40:16 +0100 Subject: [PATCH 3/9] [example] update pubspec.lock --- example/pubspec.lock | 54 +++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 1c4d2ec..bce150d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,20 +1,34 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.4.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -36,6 +50,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" cupertino_icons: dependency: "direct main" description: @@ -74,27 +95,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.3" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" path_drawing: dependency: transitive description: @@ -115,21 +143,21 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0+1" petitparser: dependency: transitive description: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "2.4.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.5" sky_engine: dependency: transitive description: flutter @@ -162,7 +190,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -176,7 +204,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -190,7 +218,7 @@ packages: path: ".." relative: true source: path - version: "1.0.1" + version: "1.0.2" vector_math: dependency: transitive description: @@ -204,7 +232,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.4.1" + version: "3.5.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.4.0 <3.0.0" flutter: ">=1.5.9-pre.94 <2.0.0" From 09dffe78868b3ad98c95a3793562803e43c542a8 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 20:47:46 +0100 Subject: [PATCH 4/9] [example] update code --- example/lib/main.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 9f61873..7bbff45 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -29,7 +29,8 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { Color color = Colors.red; - UnDrawIllustration illustration = UnDrawIllustration.mobile_application; + String illustration = '3d_modeling'; + String mode = 'offline'; @override Widget build(BuildContext context) { @@ -41,6 +42,7 @@ class _MyHomePageState extends State { body: UnDraw( color: color, illustration: illustration, + mode: mode, placeholder: Text("Illustration is loading..."), errorWidget: Icon(Icons.error_outline, color: Colors.red, size: 50), ), @@ -64,8 +66,11 @@ class _MyHomePageState extends State { onPressed: () { Random random = new Random(); setState(() { + mode = 'online'; illustration = UnDrawIllustration - .values[random.nextInt(UnDrawIllustration.values.length)]; + .values[random.nextInt(UnDrawIllustration.values.length)] + .toString() + .split('UnDrawIllustration.')[1]; }); }, backgroundColor: Colors.red, From f45b5c983eabcf1829c8d1a36a429d9300ac4de6 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 20:45:22 +0100 Subject: [PATCH 5/9] update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9d7edcf..d3b5d33 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ build/ **/ios/Flutter/flutter_assets/ **/ios/ServiceDefinitions.json **/ios/Runner/GeneratedPluginRegistrant.* +**/ios/**/flutter_export_environment.sh # Exceptions to above rules. !**/ios/**/default.mode1v3 From ee2b7c67139061469a07560816fc8c8132b63896 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 20:47:22 +0100 Subject: [PATCH 6/9] add support for offline mode --- lib/undraw.dart | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/undraw.dart b/lib/undraw.dart index 83f4f42..f7f46c5 100644 --- a/lib/undraw.dart +++ b/lib/undraw.dart @@ -1,6 +1,7 @@ library undraw; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:http/http.dart' as http; import 'package:undraw/illustrations.dart'; @@ -12,6 +13,7 @@ class UnDraw extends StatelessWidget { Key key, @required this.illustration, @required this.color, + this.mode, this.semanticLabel, this.alignment = Alignment.center, this.fit = BoxFit.contain, @@ -24,8 +26,9 @@ class UnDraw extends StatelessWidget { }) : assert(illustration != null), assert(color != null); - final UnDrawIllustration illustration; + final String illustration; final Color color; + final String mode; final String semanticLabel; final AlignmentGeometry alignment; final BoxFit fit; @@ -37,11 +40,23 @@ class UnDraw extends StatelessWidget { final EdgeInsets padding; Future renderIllustration(String name, Color _exColor) async { - var nameSplit = name.toString().split("UnDrawIllustration."); - var illustration = - illustrationList.where((i) => i["identifier"] == nameSplit[1]); - String url = illustration.toList()[0]["url"]; - String image = await _getSvgString(url); + String image; + String url; + if (this.mode == 'offline') { + image = await rootBundle.loadString('assets/$name'); + } else { + if (name.toString().contains('UnDrawIllustration.')) { + var nameSplit = name.toString().split("UnDrawIllustration."); + var illustration = + illustrationList.where((i) => i["identifier"] == nameSplit[1]); + url = illustration.toList()[0]["url"]; + } else { + var illustration = + illustrationList.where((i) => i["identifier"] == name); + url = illustration.toList()[0]["url"]; + } + image = await _getSvgFromUrl(url); + } String valueString = color.toString().split('(0x')[1].split(')')[0]; valueString = valueString.substring(2, valueString.length); @@ -61,7 +76,7 @@ class UnDraw extends StatelessWidget { Widget build(BuildContext context) { return Container( child: FutureBuilder( - future: renderIllustration(illustration.toString(), color), + future: renderIllustration(illustration, color), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasData) { return Container( @@ -82,7 +97,7 @@ class UnDraw extends StatelessWidget { ); } - Future _getSvgString(url) async { + Future _getSvgFromUrl(url) async { http.Response response = await http.get(url); return response.body; } From 356d22e187b9fa53fe3e9dbd6d6c159366662522 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 20:48:13 +0100 Subject: [PATCH 7/9] update pubspec.lock --- pubspec.lock | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 9ccf4a5..7a65df3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,20 +1,34 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.4.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -36,6 +50,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" flutter: dependency: "direct main" description: flutter @@ -67,27 +88,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.3" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" path_drawing: dependency: transitive description: @@ -108,21 +136,21 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0+1" petitparser: dependency: transitive description: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "2.4.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.5" sky_engine: dependency: transitive description: flutter @@ -155,7 +183,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -169,7 +197,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -190,7 +218,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.4.1" + version: "3.5.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.4.0 <3.0.0" flutter: ">=1.5.9-pre.94 <2.0.0" From 1cfd632418992557b903f856033433b1adbfc1f8 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 20:49:36 +0100 Subject: [PATCH 8/9] add grade.properties --- example/android/gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 8bd86f6..7be3d8b 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true From f305bf845b2f992f8bbeb2247faab649c4f6c720 Mon Sep 17 00:00:00 2001 From: Wesley Batista Date: Sun, 15 Mar 2020 21:05:26 +0100 Subject: [PATCH 9/9] fix file extension --- example/assets/{3d_modeling => 3d_modeling.svg} | 0 lib/undraw.dart | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename example/assets/{3d_modeling => 3d_modeling.svg} (100%) diff --git a/example/assets/3d_modeling b/example/assets/3d_modeling.svg similarity index 100% rename from example/assets/3d_modeling rename to example/assets/3d_modeling.svg diff --git a/lib/undraw.dart b/lib/undraw.dart index f7f46c5..8827a65 100644 --- a/lib/undraw.dart +++ b/lib/undraw.dart @@ -43,7 +43,7 @@ class UnDraw extends StatelessWidget { String image; String url; if (this.mode == 'offline') { - image = await rootBundle.loadString('assets/$name'); + image = await rootBundle.loadString('assets/$name.svg'); } else { if (name.toString().contains('UnDrawIllustration.')) { var nameSplit = name.toString().split("UnDrawIllustration.");