From fb7a4a51b81501b0cab642a146f0129f430a8956 Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Wed, 14 Sep 2022 11:25:59 -0600 Subject: [PATCH 01/15] Added image and Gradient as type of global fill (WIP) --- .../global_styling/colors_post_gen_task.dart | 59 +++++++++++++++---- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart index 40bdf428..e0ef3d38 100644 --- a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart +++ b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart @@ -6,6 +6,7 @@ import 'package:parabeac_core/generation/generators/value_objects/file_structure import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/file_ownership_policy.dart'; import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/path_services/path_service.dart'; import 'package:parabeac_core/generation/generators/value_objects/generation_configuration/pb_generation_configuration.dart'; +import 'package:parabeac_core/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart'; import 'package:pbdl/pbdl.dart'; import 'package:recase/recase.dart'; import 'package:uuid/uuid.dart'; @@ -13,33 +14,65 @@ import 'package:uuid/uuid.dart'; class ColorsPostGenTask extends PostGenTask { GenerationConfiguration generationConfiguration; - List colors; + List fills; ColorsPostGenTask( this.generationConfiguration, - this.colors, + this.fills, ); @override void execute() { var constColors = []; - var mainInfo = MainInfo(); + var constGradients = []; + var constImages = []; + // var mainInfo = MainInfo(); /// Format colors to be added to constants file - colors.forEach((color) { - constColors.add(ConstantHolder( - 'Color', - color.name.camelCase, - 'Color(${color.color.toHex()})', - description: color.description, - )); + fills.forEach((fill) { + // To add Constant Colors + if (fill is PBDLGlobalColor) { + constColors.add(ConstantHolder( + 'Color', + fill.name.camelCase, + 'Color(${fill.color.toHex()})', + description: fill.description, + )); + } + // To add Constant Images + else if (fill is PBDLGlobalImage) { + print(''); + constImages.add(ConstantHolder( + 'Image', + fill.name.camelCase, + PBFill.fromJson(fill.image.toJson()).constantGenerator(), + description: fill.description, + )); + } + // To add Constant Gradients + else if (fill is PBDLGlobalGradient) { + print(''); + constGradients.add(ConstantHolder( + 'LinearGradient', + fill.name.camelCase, + PBFill.fromJson(fill.gradient.toJson()).constantGenerator(), + description: fill.description, + )); + } }); - /// Write colors to constants file in `colors.g.dart` + /// Write list to constants file in `[$type].g.dart` + createCommand(constColors, 'colors'); + createCommand(constGradients, 'gradients'); + createCommand(constImages, 'images'); + } + + void createCommand(List list, String type) { + var mainInfo = MainInfo(); generationConfiguration.fileStructureStrategy.commandCreated( WriteConstantsCommand( Uuid().v4(), - constColors, - filename: '${mainInfo.projectName.snakeCase}_colors', + list, + filename: '${mainInfo.projectName.snakeCase}_$type', ownershipPolicy: FileOwnership.PBC, imports: 'import \'package:flutter/material.dart\';', relativePath: GetIt.I.get().themingRelativePath, From af87d7a9974d5700ab75fd6f5c8188878e37a02d Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Wed, 14 Sep 2022 11:26:30 -0600 Subject: [PATCH 02/15] Added constant for Image and Gradient (WIP) still needs to generate the actual code --- .../intermediate_fill.dart | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart b/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart index 687752fc..9c9b0759 100644 --- a/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart +++ b/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart @@ -1,6 +1,8 @@ import 'dart:math'; +import 'package:parabeac_core/controllers/main_info.dart'; import 'package:parabeac_core/interpret_and_optimize/helpers/pb_color.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:parabeac_core/interpret_and_optimize/helpers/pb_image_reference_storage.dart'; part 'intermediate_fill.g.dart'; @@ -10,7 +12,7 @@ class PBFill { @JsonKey(fromJson: _pointsFromJson, toJson: _pointsToJson) List gradientHandlePositions; - // String that tidentifies the ID of the image + // String that identifies the ID of the image String imageRef; PBColor color; @@ -34,7 +36,12 @@ class PBFill { this.isEnabled, this.color, this.imageRef, - }); + }) { + if (imageRef != null && imageRef.isNotEmpty) { + ImageReferenceStorage().addReference(imageRef.replaceAll('images/', ''), + '${MainInfo().outputPath}assets/images'); + } + } @override factory PBFill.fromJson(Map json) => _$PBFillFromJson(json); @@ -58,6 +65,15 @@ class PBFill { } return maps; } + + String constantGenerator() { + if (imageRef != null) { + return 'Image()'; + } else if (type.toLowerCase().contains('gradient')) { + return 'Gradient()'; + } + return '//TODO'; + } } @JsonSerializable() From 7e2be2f53628c7df1469896576c9ae808a0663b0 Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Mon, 19 Sep 2022 18:15:27 -0600 Subject: [PATCH 03/15] Created append to yaml post gen task --- .../append_to_yaml_post_gen_task.dart | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart b/lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart new file mode 100644 index 00000000..b7177639 --- /dev/null +++ b/lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart @@ -0,0 +1,49 @@ +import 'dart:io'; + +import 'package:parabeac_core/controllers/main_info.dart'; +import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/post_gen_task.dart'; +import 'package:yaml_modify/yaml_modify.dart'; + +class AppendToYamlPostGenTask implements PostGenTask { + // List of assets to be append to the yaml + static List assets = []; + + // TODO: WIP for when we add dependencies on the future + Map dependeciens = {}; + + @override + void execute() { + var yamlAbsPath = MainInfo().genProjectPath + '/pubspec.yaml'; + var yamlStr = File(yamlAbsPath).readAsStringSync(); + var modifiableyaml = getModifiableNode(loadYaml(yamlStr)) as Map; + + if (modifiableyaml.containsKey('flutter') && assets.isNotEmpty) { + /// Add only elements that are not already in the yaml + if (modifiableyaml['flutter'].containsKey('assets') && + modifiableyaml['flutter']['assets'] != null) { + var existingAssets = (modifiableyaml['flutter']['assets'] as List); + assets.forEach((asset) { + if (!existingAssets.any((e) => e.endsWith('/$asset'))) { + existingAssets + .add('packages/${MainInfo().projectName}/assets/images/$asset'); + } + }); + } + + /// Add all elements to the yaml + else { + modifiableyaml['flutter']['assets'] = assets + .map((e) => 'packages/${MainInfo().projectName}/assets/images/$e') + .toList(); + } + } + + /// Write the new yaml file + File(yamlAbsPath).writeAsStringSync(toYamlString(modifiableyaml)); + print('hello'); + } + + static void addAsset(String name) { + assets.add(name); + } +} From 3bc5d109a33f7fe6cb3a59eaa21598f47016b49d Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Mon, 19 Sep 2022 18:15:54 -0600 Subject: [PATCH 04/15] Pass the right asset information to get generated for the global fill --- .../global_styling/colors_post_gen_task.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart index e0ef3d38..a63913d4 100644 --- a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart +++ b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart @@ -1,11 +1,13 @@ import 'package:get_it/get_it.dart'; import 'package:parabeac_core/analytics/amplitude_analytics_service.dart'; import 'package:parabeac_core/controllers/main_info.dart'; +import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/post_gen_task.dart'; import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart'; import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/file_ownership_policy.dart'; import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/path_services/path_service.dart'; import 'package:parabeac_core/generation/generators/value_objects/generation_configuration/pb_generation_configuration.dart'; +import 'package:parabeac_core/interpret_and_optimize/helpers/pb_image_reference_storage.dart'; import 'package:parabeac_core/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart'; import 'package:pbdl/pbdl.dart'; import 'package:recase/recase.dart'; @@ -40,13 +42,18 @@ class ColorsPostGenTask extends PostGenTask { } // To add Constant Images else if (fill is PBDLGlobalImage) { - print(''); + var imageFill = PBFill.fromJson(fill.image.toJson()); constImages.add(ConstantHolder( 'Image', fill.name.camelCase, - PBFill.fromJson(fill.image.toJson()).constantGenerator(), + imageFill.constantGenerator(), description: fill.description, + isconst: false, )); + if (imageFill.imageRef != null && imageFill.imageRef.isNotEmpty) { + AppendToYamlPostGenTask.addAsset( + imageFill.imageRef.replaceAll('images/', '')); + } } // To add Constant Gradients else if (fill is PBDLGlobalGradient) { From fb738c178a2c00c312f1cfe7d0f69ef64187568e Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Mon, 19 Sep 2022 18:16:08 -0600 Subject: [PATCH 05/15] Added append to yaml to postGen --- .../global_styling/global_styling_aggregator.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart index ecd02367..38921070 100644 --- a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart +++ b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart @@ -1,6 +1,7 @@ import 'package:get_it/get_it.dart'; import 'package:parabeac_core/analytics/amplitude_analytics_service.dart'; import 'package:parabeac_core/generation/flutter_project_builder/flutter_project_builder.dart'; +import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/text_styles_post_gen_task.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/theming_post_gen_task.dart'; @@ -68,6 +69,9 @@ class GlobalStylingAggregator { globalColors, ), ); + builder.postGenTasks.add( + AppendToYamlPostGenTask(), + ); } /// Check whether there are theme or global textstyles From d5fa59ba7079b7e322f923d32e557cc172ae6bc5 Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Mon, 19 Sep 2022 18:16:28 -0600 Subject: [PATCH 06/15] Write the asset ref to the global image --- .../auxilary_data_helpers/intermediate_fill.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart b/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart index 9c9b0759..5189beed 100644 --- a/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart +++ b/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart @@ -68,7 +68,7 @@ class PBFill { String constantGenerator() { if (imageRef != null) { - return 'Image()'; + return 'Image.asset(\'$imageRef\')'; } else if (type.toLowerCase().contains('gradient')) { return 'Gradient()'; } From a1cb8da931e260e0757f4bc91baba7fd4e2211ae Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Tue, 20 Sep 2022 12:23:56 -0600 Subject: [PATCH 07/15] corrected spaces --- .../file_structure_strategy/commands/add_constant_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart b/lib/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart index 3f5b7e22..17e7a1da 100644 --- a/lib/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart +++ b/lib/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart @@ -54,7 +54,7 @@ class WriteConstantsCommand extends FileStructureCommand { var description = constant.description.isNotEmpty ? '/// ${constant.description}' : ''; var constStr = - 'static ${constant.isconst ? 'const' : ''} ${constant.type} ${constant.name} = ${constant.value};'; + 'static ${constant.isconst ? 'const ' : ''}${constant.type} ${constant.name} = ${constant.value};'; constBuffer.writeln('$description\n$constStr'); }); From 12095b31c20e9a4552a102e9fcdb36de831bc1ad Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Thu, 22 Sep 2022 17:46:35 -0600 Subject: [PATCH 08/15] Removed print statement --- .../comp_isolation/append_to_yaml_post_gen_task.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart b/lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart index b7177639..028ee12d 100644 --- a/lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart +++ b/lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart @@ -40,7 +40,6 @@ class AppendToYamlPostGenTask implements PostGenTask { /// Write the new yaml file File(yamlAbsPath).writeAsStringSync(toYamlString(modifiableyaml)); - print('hello'); } static void addAsset(String name) { From 07f62c2aedb7592f2c4cbaeaf234ce92ebc1a1ab Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Thu, 22 Sep 2022 17:46:53 -0600 Subject: [PATCH 09/15] Changed function name and change gradient with its type --- .../global_styling/colors_post_gen_task.dart | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart index a63913d4..ad784189 100644 --- a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart +++ b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart @@ -46,10 +46,11 @@ class ColorsPostGenTask extends PostGenTask { constImages.add(ConstantHolder( 'Image', fill.name.camelCase, - imageFill.constantGenerator(), + imageFill.initializerGenerator(), description: fill.description, isconst: false, )); + // Append image path to yaml so it can get expose to be used if (imageFill.imageRef != null && imageFill.imageRef.isNotEmpty) { AppendToYamlPostGenTask.addAsset( imageFill.imageRef.replaceAll('images/', '')); @@ -57,11 +58,11 @@ class ColorsPostGenTask extends PostGenTask { } // To add Constant Gradients else if (fill is PBDLGlobalGradient) { - print(''); + var gradientFill = PBFill.fromJson(fill.gradient.toJson()); constGradients.add(ConstantHolder( - 'LinearGradient', + _interpretType(gradientFill.type), fill.name.camelCase, - PBFill.fromJson(fill.gradient.toJson()).constantGenerator(), + gradientFill.initializerGenerator(), description: fill.description, )); } @@ -73,6 +74,19 @@ class ColorsPostGenTask extends PostGenTask { createCommand(constImages, 'images'); } + String _interpretType(String type) { + switch (type) { + case 'GRADIENT_LINEAR': + return 'LinearGradient'; + case 'GRADIENT_RADIAL': + return 'RadialGradient'; + case 'GRADIENT_ANGULAR': + return 'SweepGradient'; + default: + return 'Gradient'; + } + } + void createCommand(List list, String type) { var mainInfo = MainInfo(); generationConfiguration.fileStructureStrategy.commandCreated( From ca9b82b403a41ece73f944c1e801353856d481f7 Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Thu, 22 Sep 2022 17:47:04 -0600 Subject: [PATCH 10/15] Created gradient code generation --- .../intermediate_fill.dart | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart b/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart index 5189beed..2937475e 100644 --- a/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart +++ b/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart @@ -66,14 +66,59 @@ class PBFill { return maps; } - String constantGenerator() { + String initializerGenerator() { if (imageRef != null) { return 'Image.asset(\'$imageRef\')'; } else if (type.toLowerCase().contains('gradient')) { - return 'Gradient()'; + return _interpretGradient(); } return '//TODO'; } + + String _interpretGradient() { + if (type.toLowerCase().contains('radial')) { + print('radial'); + return ''' +RadialGradient( + center: Alignment(0.0, 0.0), + ${_getColorsAndStops(gradientStops)} +) + '''; + } else if (type.toLowerCase().contains('linear')) { + print('linear'); + return ''' +LinearGradient( + begin: Alignment(${gradientHandlePositions[0].x}, ${gradientHandlePositions[0].y}), + end: Alignment(${gradientHandlePositions[1].x}, ${gradientHandlePositions[1].y}), + ${_getColorsAndStops(gradientStops)} +) +'''; + // + } else if (type.toLowerCase().contains('angular')) { + // TODO: add support for angular gradient + return 'SweepGradient(colors: []) // We will support it in the future'; + } else { + // Empty gradient TODO: + return 'null /* Not supported gradient */'; + } + } + + String _getColorsAndStops(List gradientStops) { + var colors = ''; + var stops = ''; + for (var stop in gradientStops) { + colors += 'Color(' + stop.color.toString() + '),'; + stops += stop.position.toString() + ','; + } + return ''' +colors: [ + $colors + ], + stops: [ + $stops + ], +'''; + } } @JsonSerializable() From ca7b1379b72b360b66148c6267b333c1b712d738 Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Thu, 29 Sep 2022 17:15:04 -0600 Subject: [PATCH 11/15] Created global effect post gen task --- .../global_effects_post_gen_task.dart | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart new file mode 100644 index 00000000..b98326e9 --- /dev/null +++ b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart @@ -0,0 +1,132 @@ +import 'package:get_it/get_it.dart'; +import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/post_gen_task.dart'; +import 'package:parabeac_core/generation/generators/attribute-helper/pb_color_gen_helper.dart'; +import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart'; +import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/file_ownership_policy.dart'; +import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/path_services/path_service.dart'; +import 'package:parabeac_core/generation/generators/value_objects/generation_configuration/pb_generation_configuration.dart'; +import 'package:parabeac_core/interpret_and_optimize/helpers/pb_color.dart'; +import 'package:pbdl/pbdl.dart'; +import 'package:recase/recase.dart'; +import 'package:uuid/uuid.dart'; + +import '../../../../controllers/main_info.dart'; + +class EffectsPostGenTask extends PostGenTask { + GenerationConfiguration generationConfiguration; + List effects; + + EffectsPostGenTask( + this.generationConfiguration, + this.effects, + ); + + @override + void execute() { + var constLayerBlurs = []; + var constBackgroundBlurs = []; + var constDropShadows = []; + var constInnerShadows = []; + + /// Go through each effect + effects.forEach((effect) { + switch (effect.effect.type) { + case 'LAYER_BLUR': + constLayerBlurs.add(ConstantHolder( + 'ImageFiltered', + effect.name.camelCase + '(Widget child)', + _getLayerBlur(effect.effect), + description: effect.description, + isconst: false, + isFunction: true, + )); + break; + case 'BACKGROUND_BLUR': + constBackgroundBlurs.add(ConstantHolder( + 'ClipRect', + effect.name.camelCase + '(Widget child)', + _getBackgroundBlur(effect.effect), + description: effect.description, + isconst: false, + isFunction: true, + )); + break; + case 'DROP_SHADOW': + constDropShadows.add(ConstantHolder( + 'BoxShadow', + effect.name.camelCase.toLowerCase(), + _getDropShadow(effect.effect), + description: effect.description, + )); + break; + + case 'INNER_SHADOW': + + /// TODO: Empty for now + break; + default: + } + }); + + /// Write list to constants file in `[$type].g.dart` + createCommand(constLayerBlurs, 'layer_blur', + imports: ['import \'dart:ui\';']); + createCommand(constBackgroundBlurs, 'background_blur', + imports: ['import \'dart:ui\';']); + createCommand(constDropShadows, 'drop_shadow'); + } + + void createCommand(List list, String type, + {List imports}) { + var mainInfo = MainInfo(); + generationConfiguration.fileStructureStrategy.commandCreated( + WriteConstantsCommand( + Uuid().v4(), + list, + filename: '${mainInfo.projectName.snakeCase}_$type', + ownershipPolicy: FileOwnership.PBC, + imports: 'import \'package:flutter/material.dart\';\n' + + ((imports != null) ? imports.join() : '\n'), + relativePath: GetIt.I.get().themingRelativePath, + ), + ); + } + + String _getLayerBlur(var effect) { + return ''' +ImageFiltered( + imageFilter: ImageFilter.blur( + sigmaX: ${effect.radius}, + sigmaY: ${effect.radius}, + ), + child: child, +) +'''; + } + + String _getBackgroundBlur(var effect) { + return ''' +ClipRect( + child: BackdropFilter( + filter: ImageFilter.blur( + sigmaX: ${effect.radius}, + sigmaY: ${effect.radius}, + ), + child: child, + ) +) +'''; + } + + String _getDropShadow(var effect) { + var color = PBColor.fromJson(effect.color.toJson()); + return ''' +BoxShadow( + offset: Offset(${effect.offset['x']}, ${effect.offset['y']}), + ${PBColorGenHelper().getHexColor(color)} + spreadRadius: 0.0, + blurRadius: ${effect.radius}, +) +'''; + } +} From e5bd78da6d45e46046602b1aaa167c33324bf137 Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Thu, 29 Sep 2022 17:15:16 -0600 Subject: [PATCH 12/15] Added effect post task --- .../global_styling/global_styling_aggregator.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart index 38921070..d2a6fe7d 100644 --- a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart +++ b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart @@ -3,6 +3,7 @@ import 'package:parabeac_core/analytics/amplitude_analytics_service.dart'; import 'package:parabeac_core/generation/flutter_project_builder/flutter_project_builder.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/append_to_yaml_post_gen_task.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart'; +import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/text_styles_post_gen_task.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/theming_post_gen_task.dart'; import 'package:pbdl/pbdl.dart'; @@ -74,6 +75,16 @@ class GlobalStylingAggregator { ); } + /// Check whether there are global effects + if (globalStyles.effects != null && globalStyles.effects.isNotEmpty) { + builder.postGenTasks.add( + EffectsPostGenTask( + builder.generationConfiguration, + globalStyles.effects, + ), + ); + } + /// Check whether there are theme or global textstyles if ((globalStyles.textStyles != null && globalStyles.textStyles.isNotEmpty) || From 6f17e243976701196f7bbba03f11d6361eda3396 Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Thu, 29 Sep 2022 17:15:32 -0600 Subject: [PATCH 13/15] Added support for functions --- .../commands/add_constant_command.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart b/lib/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart index 17e7a1da..d870d3be 100644 --- a/lib/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart +++ b/lib/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart @@ -54,7 +54,7 @@ class WriteConstantsCommand extends FileStructureCommand { var description = constant.description.isNotEmpty ? '/// ${constant.description}' : ''; var constStr = - 'static ${constant.isconst ? 'const ' : ''}${constant.type} ${constant.name} = ${constant.value};'; + 'static ${constant.isconst ? 'const ' : ''}${constant.type} ${constant.name} =${constant.isFunction ? '>' : ''} ${constant.value};'; constBuffer.writeln('$description\n$constStr'); }); @@ -90,11 +90,15 @@ class ConstantHolder { /// Whether [this] should have "const" written in it. bool isconst; //TODO: Temporary bool in order to write theming file. + /// Whether [this] is declaring a funciton or a variable + bool isFunction; + ConstantHolder( this.type, this.name, this.value, { this.isconst = true, this.description = '', + this.isFunction = false, }); } From 0a8f40afbd0b1132f95c9fe841551370f799af1c Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Thu, 29 Sep 2022 17:15:44 -0600 Subject: [PATCH 14/15] Removed print statements and fix output --- .../auxilary_data_helpers/intermediate_fill.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart b/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart index 2937475e..882edb11 100644 --- a/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart +++ b/lib/interpret_and_optimize/state_management/auxilary_data_helpers/intermediate_fill.dart @@ -77,7 +77,6 @@ class PBFill { String _interpretGradient() { if (type.toLowerCase().contains('radial')) { - print('radial'); return ''' RadialGradient( center: Alignment(0.0, 0.0), @@ -85,7 +84,6 @@ RadialGradient( ) '''; } else if (type.toLowerCase().contains('linear')) { - print('linear'); return ''' LinearGradient( begin: Alignment(${gradientHandlePositions[0].x}, ${gradientHandlePositions[0].y}), @@ -96,7 +94,7 @@ LinearGradient( // } else if (type.toLowerCase().contains('angular')) { // TODO: add support for angular gradient - return 'SweepGradient(colors: []) // We will support it in the future'; + return 'SweepGradient(colors: []); // We will support it in the future'; } else { // Empty gradient TODO: return 'null /* Not supported gradient */'; From 6a7addecb9fdd5064b683effa77d809f79a3e2f2 Mon Sep 17 00:00:00 2001 From: Bryan Figueroa Date: Thu, 29 Sep 2022 17:26:20 -0600 Subject: [PATCH 15/15] Output effects on their respective directory --- .../global_styling/global_effects_post_gen_task.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart index b98326e9..8af91deb 100644 --- a/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart +++ b/lib/generation/flutter_project_builder/post_gen_tasks/global_styling/global_effects_post_gen_task.dart @@ -1,4 +1,5 @@ import 'package:get_it/get_it.dart'; +import 'package:parabeac_core/controllers/main_info.dart'; import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/post_gen_task.dart'; import 'package:parabeac_core/generation/generators/attribute-helper/pb_color_gen_helper.dart'; import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart'; @@ -9,8 +10,7 @@ import 'package:parabeac_core/interpret_and_optimize/helpers/pb_color.dart'; import 'package:pbdl/pbdl.dart'; import 'package:recase/recase.dart'; import 'package:uuid/uuid.dart'; - -import '../../../../controllers/main_info.dart'; +import 'package:path/path.dart' as path; class EffectsPostGenTask extends PostGenTask { GenerationConfiguration generationConfiguration; @@ -87,7 +87,8 @@ class EffectsPostGenTask extends PostGenTask { ownershipPolicy: FileOwnership.PBC, imports: 'import \'package:flutter/material.dart\';\n' + ((imports != null) ? imports.join() : '\n'), - relativePath: GetIt.I.get().themingRelativePath, + relativePath: path.join( + GetIt.I.get().themingRelativePath, 'effects'), ), ); }