From 90c132e47e2bdb7635916953b63f80942b4f1aa0 Mon Sep 17 00:00:00 2001 From: nekocode Date: Tue, 8 Sep 2020 08:17:18 +0800 Subject: [PATCH 1/2] Add a special case in unit-test --- test/flutter_gen_test.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/flutter_gen_test.dart b/test/flutter_gen_test.dart index 35b930f3..f2afbaf8 100644 --- a/test/flutter_gen_test.dart +++ b/test/flutter_gen_test.dart @@ -146,6 +146,14 @@ void main() { }); test('Assets with No inegrations on pubspec.yaml', () async { + await FlutterGenerator( + File('test_resources/pubspec_assets_no_integrations.yaml')) + .build(); + expect( + File('test_resources/lib/gen/assets.gen.dart').readAsStringSync(), + isNotEmpty, + ); + final pubspec = File('test_resources/pubspec_assets_no_integrations.yaml'); final config = await Config(pubspec).load(); final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength); From 2552acaea8f98fe55a7cae69caf2f49e1212b7d9 Mon Sep 17 00:00:00 2001 From: nekocode Date: Tue, 8 Sep 2020 11:20:18 +0800 Subject: [PATCH 2/2] Fix #21 --- lib/src/settings/flutter.dart | 8 ++++++-- lib/src/settings/flutter_gen.dart | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/src/settings/flutter.dart b/lib/src/settings/flutter.dart index eca40c85..2e5692bf 100644 --- a/lib/src/settings/flutter.dart +++ b/lib/src/settings/flutter.dart @@ -4,8 +4,12 @@ import 'package:yaml/yaml.dart'; class Flutter { Flutter(YamlMap flutterMap) { if (flutterMap != null) { - assets = FlutterAssets(safeCast(flutterMap['assets'])); - fonts = FlutterFonts(safeCast(flutterMap['fonts'])); + if (flutterMap.containsKey('assets')) { + assets = FlutterAssets(safeCast(flutterMap['assets'])); + } + if (flutterMap.containsKey('fonts')) { + fonts = FlutterFonts(safeCast(flutterMap['fonts'])); + } } } diff --git a/lib/src/settings/flutter_gen.dart b/lib/src/settings/flutter_gen.dart index 974ed30a..016a9266 100644 --- a/lib/src/settings/flutter_gen.dart +++ b/lib/src/settings/flutter_gen.dart @@ -8,10 +8,14 @@ class FlutterGen { FlutterGen(YamlMap flutterGenMap) { if (flutterGenMap != null) { _output = safeCast(flutterGenMap['output']); - integrations = FlutterGenIntegrations( + if (flutterGenMap.containsKey('integrations')) { + integrations = FlutterGenIntegrations( safeCast(flutterGenMap['integrations'])); + } _lineLength = safeCast(flutterGenMap['lineLength']); - colors = FlutterGenColors(safeCast(flutterGenMap['colors'])); + if (flutterGenMap.containsKey('colors')) { + colors = FlutterGenColors(safeCast(flutterGenMap['colors'])); + } } }