diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 15f9c89..82521be 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -12,3 +12,13 @@ jobs: - uses: actions/checkout@v3 - name: Validate uses: peiffer-innovations/actions-flutter-validate@v1 + with: + path: annotation + - name: Validate + uses: peiffer-innovations/actions-flutter-validate@v1 + with: + path: codegen + - name: Validate + uses: peiffer-innovations/actions-flutter-validate@v1 + with: + path: json_theme diff --git a/json_theme/CHANGELOG.md b/json_theme/CHANGELOG.md index 5b76496..2d3f33e 100644 --- a/json_theme/CHANGELOG.md +++ b/json_theme/CHANGELOG.md @@ -1,3 +1,10 @@ +## [6.3.0] - September 27th, 2023 + +* Added codecs for: + * `BoxHeightStyle` + * `BoxWidthStyle` + + ## [6.2.6+1] - September 12th, 2023 * Switching back to [json_schema](https://pub.dev/packages/json_schema) diff --git a/json_theme/lib/src/codec/theme_decoder.dart b/json_theme/lib/src/codec/theme_decoder.dart index b222dd3..269fc32 100644 --- a/json_theme/lib/src/codec/theme_decoder.dart +++ b/json_theme/lib/src/codec/theme_decoder.dart @@ -1770,6 +1770,53 @@ class ThemeDecoder { return result; } + /// Decodes the [value] to a [BoxHeightStyle]. Supported values are: + /// * `includeLineSpacingBottom` + /// * `includeLineSpacingMiddle` + /// * `includeLineSpacingTop` + /// * `max` + /// * `strut` + /// * `tight` + static BoxHeightStyle? decodeBoxHeightStyle( + dynamic value, { + bool validate = false, + }) { + BoxHeightStyle? result; + + if (value is BoxHeightStyle) { + result = value; + } else if (value != null) { + assert(SchemaValidator.validate( + schemaId: '$_baseSchemaUrl/box_height_style', + value: value, + validate: validate, + )); + + switch (value) { + case 'includeLineSpacingBottom': + result = BoxHeightStyle.includeLineSpacingBottom; + break; + case 'includeLineSpacingMiddle': + result = BoxHeightStyle.includeLineSpacingMiddle; + break; + case 'includeLineSpacingTop': + result = BoxHeightStyle.includeLineSpacingTop; + break; + case 'max': + result = BoxHeightStyle.max; + break; + case 'strut': + result = BoxHeightStyle.strut; + break; + case 'tight': + result = BoxHeightStyle.tight; + break; + } + } + + return result; + } + /// Decodes the given [value] into a [BoxDecoration]. If the value is `null` /// then `null` will be returned. Otherwise, this expects a Map like value /// that in JSON would look like: @@ -1857,6 +1904,37 @@ class ThemeDecoder { return result; } + /// Decodes the [value] to a [BoxWidthStyle]. Supported values are: + /// * `max` + /// * `tight` + static BoxWidthStyle? decodeBoxWidthStyle( + dynamic value, { + bool validate = false, + }) { + BoxWidthStyle? result; + + if (value is BoxWidthStyle) { + result = value; + } else if (value != null) { + assert(SchemaValidator.validate( + schemaId: '$_baseSchemaUrl/box_width_style', + value: value, + validate: validate, + )); + + switch (value) { + case 'max': + result = BoxWidthStyle.max; + break; + case 'tight': + result = BoxWidthStyle.tight; + break; + } + } + + return result; + } + /// Decodes the [value] to a [Brightness]. Supported values are: /// * `light` /// * `dark` diff --git a/json_theme/lib/src/codec/theme_encoder.dart b/json_theme/lib/src/codec/theme_encoder.dart index 30a596f..b1e5f63 100644 --- a/json_theme/lib/src/codec/theme_encoder.dart +++ b/json_theme/lib/src/codec/theme_encoder.dart @@ -924,6 +924,42 @@ class ThemeEncoder { return _stripDynamicNull(result); } + /// Encodes the [value] to a `String`. Supported values are: + /// * `includeLineSpacingBottom` + /// * `includeLineSpacingMiddle` + /// * `includeLineSpacingTop` + /// * `max` + /// * `strut` + /// * `tight` + static String? encodeBoxHeightStyle(BoxHeightStyle? value) { + String? result; + + if (value != null) { + switch (value) { + case BoxHeightStyle.includeLineSpacingBottom: + result = 'includeLineSpacingBottom'; + break; + case BoxHeightStyle.includeLineSpacingMiddle: + result = 'includeLineSpacingMiddle'; + break; + case BoxHeightStyle.includeLineSpacingTop: + result = 'includeLineSpacingTop'; + break; + case BoxHeightStyle.max: + result = 'max'; + break; + case BoxHeightStyle.strut: + result = 'strut'; + break; + case BoxHeightStyle.tight: + result = 'tight'; + break; + } + } + + return result; + } + /// Encodes the given [value] into a JSON compatible map. This produces a Map /// in the following format: /// @@ -977,6 +1013,26 @@ class ThemeEncoder { return _stripDynamicNull(result); } + /// Encodes the [value] to a `String`. Supported values are: + /// * `max` + /// * `tight` + static String? encodeBoxWidthStyle(BoxWidthStyle? value) { + String? result; + + if (value != null) { + switch (value) { + case BoxWidthStyle.max: + result = 'max'; + break; + case BoxWidthStyle.tight: + result = 'tight'; + break; + } + } + + return result; + } + /// Encodes the given [value] to the String representation. Supported values /// are: /// * `dark` diff --git a/json_theme/lib/src/schema/all.dart b/json_theme/lib/src/schema/all.dart index 253caf7..b154e31 100644 --- a/json_theme/lib/src/schema/all.dart +++ b/json_theme/lib/src/schema/all.dart @@ -8,7 +8,9 @@ export 'schemas/enums/border_style_schema.dart'; export 'schemas/enums/bottom_navigation_bar_landscape_layout.dart'; export 'schemas/enums/bottom_navigation_bar_type_schema.dart'; export 'schemas/enums/box_fit_schema.dart'; +export 'schemas/enums/box_height_style_schema.dart'; export 'schemas/enums/box_shape_schema.dart'; +export 'schemas/enums/box_width_style_schema.dart'; export 'schemas/enums/brightness_schema.dart'; export 'schemas/enums/button_bar_layout_behavior_schema.dart'; export 'schemas/enums/button_text_theme_schema.dart'; diff --git a/json_theme/lib/src/schema/schemas/enums.dart b/json_theme/lib/src/schema/schemas/enums.dart index 2aa5aad..faf5bdb 100644 --- a/json_theme/lib/src/schema/schemas/enums.dart +++ b/json_theme/lib/src/schema/schemas/enums.dart @@ -13,7 +13,9 @@ class Enums { BottomNavigationBarLandscapeLayoutSchema.id, BottomNavigationBarTypeSchema.id, BoxFitSchema.id, + BoxHeightStyleSchema.id, BoxShapeSchema.id, + BoxWidthStyleSchema.id, BrightnessSchema.id, ButtonBarLayoutBehaviorSchema.id, ButtonTextThemeSchema.id, diff --git a/json_theme/lib/src/schema/schemas/enums/box_height_style_schema.dart b/json_theme/lib/src/schema/schemas/enums/box_height_style_schema.dart new file mode 100644 index 0000000..3b2bed0 --- /dev/null +++ b/json_theme/lib/src/schema/schemas/enums/box_height_style_schema.dart @@ -0,0 +1,21 @@ +import 'package:json_theme/json_theme_schemas.dart'; + +class BoxHeightStyleSchema { + static const id = + 'https://peiffer-innovations.github.io/flutter_json_schemas/schemas/json_theme/box_height_style.json'; + + static final schema = { + r'$schema': 'http://json-schema.org/draft-07/schema#', + r'$id': id, + 'type': 'string', + 'title': 'BoxHeightStyle', + 'oneOf': SchemaHelper.enumSchema([ + 'includeLineSpacingBottom', + 'includeLineSpacingMiddle', + 'includeLineSpacingTop', + 'max', + 'strut', + 'tight', + ]), + }; +} diff --git a/json_theme/lib/src/schema/schemas/enums/box_width_style_schema.dart b/json_theme/lib/src/schema/schemas/enums/box_width_style_schema.dart new file mode 100644 index 0000000..547c982 --- /dev/null +++ b/json_theme/lib/src/schema/schemas/enums/box_width_style_schema.dart @@ -0,0 +1,17 @@ +import 'package:json_theme/json_theme_schemas.dart'; + +class BoxWidthStyleSchema { + static const id = + 'https://peiffer-innovations.github.io/flutter_json_schemas/schemas/json_theme/box_width_style.json'; + + static final schema = { + r'$schema': 'http://json-schema.org/draft-07/schema#', + r'$id': id, + 'type': 'string', + 'title': 'BoxWidthStyle', + 'oneOf': SchemaHelper.enumSchema([ + 'max', + 'tight', + ]), + }; +} diff --git a/json_theme/pubspec.yaml b/json_theme/pubspec.yaml index f14463b..a2c7c40 100644 --- a/json_theme/pubspec.yaml +++ b/json_theme/pubspec.yaml @@ -1,7 +1,7 @@ name: 'json_theme' description: 'A library to dynamically generate a ThemeData object from a JSON file or dynamic map object' homepage: 'https://github.com/peiffer-innovations/json_theme' -version: '6.2.6+1' +version: '6.3.0' environment: sdk: '>=3.0.0 <4.0.0' @@ -24,7 +24,7 @@ dev_dependencies: analyzer: '^6.2.0' build: '^2.4.1' build_runner: '^2.4.6' - code_builder: '^4.6.0' + code_builder: '^4.7.0' flutter_lints: '^2.0.2' flutter_test: sdk: 'flutter' diff --git a/json_theme/test/json_theme_test.dart b/json_theme/test/json_theme_test.dart index fcb3d07..aef2fb2 100644 --- a/json_theme/test/json_theme_test.dart +++ b/json_theme/test/json_theme_test.dart @@ -1289,6 +1289,70 @@ void main() { expect(ThemeEncoder.encodeBoxFit(BoxFit.scaleDown), 'scaleDown'); }); + test('BoxHeightStyle', () { + expect(ThemeDecoder.decodeBoxHeightStyle(null), null); + expect(ThemeEncoder.encodeBoxHeightStyle(null), null); + + expect( + ThemeDecoder.decodeBoxHeightStyle( + BoxHeightStyle.max, + ), + BoxHeightStyle.max, + ); + + expect( + ThemeDecoder.decodeBoxHeightStyle('includeLineSpacingBottom'), + BoxHeightStyle.includeLineSpacingBottom, + ); + expect( + ThemeDecoder.decodeBoxHeightStyle('includeLineSpacingMiddle'), + BoxHeightStyle.includeLineSpacingMiddle, + ); + expect( + ThemeDecoder.decodeBoxHeightStyle('includeLineSpacingTop'), + BoxHeightStyle.includeLineSpacingTop, + ); + expect( + ThemeDecoder.decodeBoxHeightStyle('max'), + BoxHeightStyle.max, + ); + expect( + ThemeDecoder.decodeBoxHeightStyle('strut'), + BoxHeightStyle.strut, + ); + expect( + ThemeDecoder.decodeBoxHeightStyle('tight'), + BoxHeightStyle.tight, + ); + + expect( + ThemeEncoder.encodeBoxHeightStyle( + BoxHeightStyle.includeLineSpacingBottom), + 'includeLineSpacingBottom', + ); + expect( + ThemeEncoder.encodeBoxHeightStyle( + BoxHeightStyle.includeLineSpacingMiddle), + 'includeLineSpacingMiddle', + ); + expect( + ThemeEncoder.encodeBoxHeightStyle(BoxHeightStyle.includeLineSpacingTop), + 'includeLineSpacingTop', + ); + expect( + ThemeEncoder.encodeBoxHeightStyle(BoxHeightStyle.max), + 'max', + ); + expect( + ThemeEncoder.encodeBoxHeightStyle(BoxHeightStyle.strut), + 'strut', + ); + expect( + ThemeEncoder.encodeBoxHeightStyle(BoxHeightStyle.tight), + 'tight', + ); + }); + test('BoxShadow', () { expect(ThemeDecoder.decodeBoxShadow(null), null); expect(ThemeEncoder.encodeBoxShadow(null), null); @@ -1344,6 +1408,36 @@ void main() { expect(ThemeEncoder.encodeBoxShape(BoxShape.rectangle), 'rectangle'); }); + test('BoxWidthStyle', () { + expect(ThemeDecoder.decodeBoxWidthStyle(null), null); + expect(ThemeEncoder.encodeBoxWidthStyle(null), null); + + expect( + ThemeDecoder.decodeBoxWidthStyle( + BoxWidthStyle.max, + ), + BoxWidthStyle.max, + ); + + expect( + ThemeDecoder.decodeBoxWidthStyle('max'), + BoxWidthStyle.max, + ); + expect( + ThemeDecoder.decodeBoxWidthStyle('tight'), + BoxWidthStyle.tight, + ); + + expect( + ThemeEncoder.encodeBoxWidthStyle(BoxWidthStyle.max), + 'max', + ); + expect( + ThemeEncoder.encodeBoxWidthStyle(BoxWidthStyle.tight), + 'tight', + ); + }); + test('Brightness', () { expect(ThemeDecoder.decodeBrightness(null), null); expect(ThemeEncoder.encodeBrightness(null), null);