From 5886c81224a22473a8e2b85e72587a5982c9abb7 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira <62367544+tilucasoli@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:47:28 -0300 Subject: [PATCH] bring style properties to the root of TextSpecUtility --- .../attributes/text_style/text_style_dto.dart | 6 -- .../text_style/text_style_dto.g.dart | 3 - .../text_style/text_style_util.dart | 6 -- .../mix/lib/src/specs/text/text_spec.dart | 29 +++++++++ .../mix/lib/src/specs/text/text_spec.g.dart | 63 +++++++++++++++++++ .../text_style/text_style_dto_test.dart | 5 -- .../text_style/text_style_util_test.dart | 2 - 7 files changed, 92 insertions(+), 22 deletions(-) diff --git a/packages/mix/lib/src/attributes/text_style/text_style_dto.dart b/packages/mix/lib/src/attributes/text_style/text_style_dto.dart index 3a32167cc..1701e7e2d 100644 --- a/packages/mix/lib/src/attributes/text_style/text_style_dto.dart +++ b/packages/mix/lib/src/attributes/text_style/text_style_dto.dart @@ -66,7 +66,6 @@ base class TextStyleData extends Dto final TextDecoration? decoration; final ColorDto? decorationColor; final TextDecorationStyle? decorationStyle; - final Locale? locale; final String? debugLabel; final double? height; final Paint? foreground; @@ -93,7 +92,6 @@ base class TextStyleData extends Dto this.foreground, this.height, this.letterSpacing, - this.locale, this.shadows, this.textBaseline, this.wordSpacing, @@ -120,7 +118,6 @@ base class TextStyleData extends Dto properties.addUsingDefault('foreground', foreground); properties.addUsingDefault('height', height); properties.addUsingDefault('letterSpacing', letterSpacing); - properties.addUsingDefault('locale', locale); properties.addUsingDefault('shadows', shadows); properties.addUsingDefault('textBaseline', textBaseline); properties.addUsingDefault('wordSpacing', wordSpacing); @@ -156,7 +153,6 @@ final class TextStyleDto extends Dto ColorDto? decorationColor, TextDecorationStyle? decorationStyle, List? fontVariations, - Locale? locale, double? height, Paint? foreground, Paint? background, @@ -184,7 +180,6 @@ final class TextStyleDto extends Dto foreground: foreground, height: height, letterSpacing: letterSpacing, - locale: locale, shadows: shadows, textBaseline: textBaseline, wordSpacing: wordSpacing, @@ -260,7 +255,6 @@ extension TextStyleExt on TextStyle { foreground: foreground, height: height, letterSpacing: letterSpacing, - locale: locale, shadows: shadows?.map((e) => e.toDto()).toList(), textBaseline: textBaseline, wordSpacing: wordSpacing, diff --git a/packages/mix/lib/src/attributes/text_style/text_style_dto.g.dart b/packages/mix/lib/src/attributes/text_style/text_style_dto.g.dart index 748cbb17c..ebdf054bf 100644 --- a/packages/mix/lib/src/attributes/text_style/text_style_dto.g.dart +++ b/packages/mix/lib/src/attributes/text_style/text_style_dto.g.dart @@ -40,7 +40,6 @@ mixin _$TextStyleData on Dto { foreground: _$this.foreground ?? defaultValue.foreground, height: _$this.height ?? defaultValue.height, letterSpacing: _$this.letterSpacing ?? defaultValue.letterSpacing, - locale: _$this.locale ?? defaultValue.locale, shadows: _$this.shadows?.map((e) => e.resolve(mix)).toList() ?? defaultValue.shadows, textBaseline: _$this.textBaseline ?? defaultValue.textBaseline, @@ -85,7 +84,6 @@ mixin _$TextStyleData on Dto { foreground: other.foreground ?? _$this.foreground, height: other.height ?? _$this.height, letterSpacing: other.letterSpacing ?? _$this.letterSpacing, - locale: other.locale ?? _$this.locale, shadows: MixHelpers.mergeList(_$this.shadows, other.shadows), textBaseline: other.textBaseline ?? _$this.textBaseline, wordSpacing: other.wordSpacing ?? _$this.wordSpacing, @@ -116,7 +114,6 @@ mixin _$TextStyleData on Dto { _$this.foreground, _$this.height, _$this.letterSpacing, - _$this.locale, _$this.shadows, _$this.textBaseline, _$this.wordSpacing, diff --git a/packages/mix/lib/src/attributes/text_style/text_style_util.dart b/packages/mix/lib/src/attributes/text_style/text_style_util.dart index f642f80f3..70db3a5f8 100644 --- a/packages/mix/lib/src/attributes/text_style/text_style_util.dart +++ b/packages/mix/lib/src/attributes/text_style/text_style_util.dart @@ -59,8 +59,6 @@ final class TextStyleUtility T fontFeatures(List v) => call(fontFeatures: v); - T locale(Locale v) => call(locale: v); - T debugLabel(String v) => call(debugLabel: v); T decorationThickness(double v) => call(decorationThickness: v); @@ -84,7 +82,6 @@ final class TextStyleUtility List? fontFeatures, TextDecoration? decoration, TextDecorationStyle? decorationStyle, - Locale? locale, String? debugLabel, List? fontFamilyFallback, Paint? foreground, @@ -112,7 +109,6 @@ final class TextStyleUtility background: background, decorationThickness: decorationThickness, fontFamilyFallback: fontFamilyFallback, - locale: locale, debugLabel: debugLabel, height: height, fontFamily: fontFamily, @@ -139,7 +135,6 @@ final class TextStyleUtility Paint? background, double? decorationThickness, List? fontFamilyFallback, - Locale? locale, String? debugLabel, double? height, String? fontFamily, @@ -160,7 +155,6 @@ final class TextStyleUtility decorationColor: decorationColor, decorationStyle: decorationStyle, fontVariations: fontVariations, - locale: locale, height: height, foreground: foreground, background: background, diff --git a/packages/mix/lib/src/specs/text/text_spec.dart b/packages/mix/lib/src/specs/text/text_spec.dart index ab146a054..82c6488e9 100644 --- a/packages/mix/lib/src/specs/text/text_spec.dart +++ b/packages/mix/lib/src/specs/text/text_spec.dart @@ -26,6 +26,33 @@ import 'text_widget.dart'; part 'text_spec.g.dart'; +const _style = MixableUtility( + type: TextStyle, + properties: [ + (path: 'color', alias: 'color'), + (path: 'fontFamily', alias: 'fontFamily'), + (path: 'fontWeight', alias: 'fontWeight'), + (path: 'fontStyle', alias: 'fontStyle'), + (path: 'fontSize', alias: 'fontSize'), + (path: 'letterSpacing', alias: 'letterSpacing'), + (path: 'wordSpacing', alias: 'wordSpacing'), + (path: 'textBaseline', alias: 'textBaseline'), + (path: 'backgroundColor', alias: 'backgroundColor'), + (path: 'shadows', alias: 'shadows'), + (path: 'fontFeatures', alias: 'fontFeatures'), + (path: 'fontVariations', alias: 'fontVariations'), + (path: 'decoration', alias: 'decoration'), + (path: 'decorationColor', alias: 'decorationColor'), + (path: 'decorationStyle', alias: 'decorationStyle'), + (path: 'debugLabel', alias: 'debugLabel'), + (path: 'height', alias: 'height'), + (path: 'foreground', alias: 'foreground'), + (path: 'background', alias: 'background'), + (path: 'decorationThickness', alias: 'decorationThickness'), + (path: 'fontFamilyFallback', alias: 'fontFamilyFallback'), + ], +); + @MixableSpec() final class TextSpec extends Spec with _$TextSpec, Diagnosticable { final TextOverflow? overflow; @@ -34,6 +61,8 @@ final class TextSpec extends Spec with _$TextSpec, Diagnosticable { final int? maxLines; final TextWidthBasis? textWidthBasis; final TextScaler? textScaler; + + @MixableProperty(utilities: [_style]) final TextStyle? style; final TextDirection? textDirection; final bool? softWrap; diff --git a/packages/mix/lib/src/specs/text/text_spec.g.dart b/packages/mix/lib/src/specs/text/text_spec.g.dart index 317e6308b..8fa8b6629 100644 --- a/packages/mix/lib/src/specs/text/text_spec.g.dart +++ b/packages/mix/lib/src/specs/text/text_spec.g.dart @@ -353,6 +353,69 @@ class TextSpecUtility /// Utility for defining [TextSpecAttribute.style] late final style = TextStyleUtility((v) => only(style: v)); + /// Utility for defining [TextSpecAttribute.style.color] + late final color = style.color; + + /// Utility for defining [TextSpecAttribute.style.fontFamily] + late final fontFamily = style.fontFamily; + + /// Utility for defining [TextSpecAttribute.style.fontWeight] + late final fontWeight = style.fontWeight; + + /// Utility for defining [TextSpecAttribute.style.fontStyle] + late final fontStyle = style.fontStyle; + + /// Utility for defining [TextSpecAttribute.style.fontSize] + late final fontSize = style.fontSize; + + /// Utility for defining [TextSpecAttribute.style.letterSpacing] + late final letterSpacing = style.letterSpacing; + + /// Utility for defining [TextSpecAttribute.style.wordSpacing] + late final wordSpacing = style.wordSpacing; + + /// Utility for defining [TextSpecAttribute.style.textBaseline] + late final textBaseline = style.textBaseline; + + /// Utility for defining [TextSpecAttribute.style.backgroundColor] + late final backgroundColor = style.backgroundColor; + + /// Utility for defining [TextSpecAttribute.style.shadows] + late final shadows = style.shadows; + + /// Utility for defining [TextSpecAttribute.style.fontFeatures] + late final fontFeatures = style.fontFeatures; + + /// Utility for defining [TextSpecAttribute.style.fontVariations] + late final fontVariations = style.fontVariations; + + /// Utility for defining [TextSpecAttribute.style.decoration] + late final decoration = style.decoration; + + /// Utility for defining [TextSpecAttribute.style.decorationColor] + late final decorationColor = style.decorationColor; + + /// Utility for defining [TextSpecAttribute.style.decorationStyle] + late final decorationStyle = style.decorationStyle; + + /// Utility for defining [TextSpecAttribute.style.debugLabel] + late final debugLabel = style.debugLabel; + + /// Utility for defining [TextSpecAttribute.style.height] + late final height = style.height; + + /// Utility for defining [TextSpecAttribute.style.foreground] + late final foreground = style.foreground; + + /// Utility for defining [TextSpecAttribute.style.background] + late final background = style.background; + + /// Utility for defining [TextSpecAttribute.style.decorationThickness] + late final decorationThickness = style.decorationThickness; + + /// Utility for defining [TextSpecAttribute.style.fontFamilyFallback] + late final fontFamilyFallback = style.fontFamilyFallback; + /// Utility for defining [TextSpecAttribute.textWidthBasis] late final textWidthBasis = TextWidthBasisUtility((v) => only(textWidthBasis: v)); diff --git a/packages/mix/test/src/attributes/text_style/text_style_dto_test.dart b/packages/mix/test/src/attributes/text_style/text_style_dto_test.dart index 06c0b3f84..1816e3e99 100644 --- a/packages/mix/test/src/attributes/text_style/text_style_dto_test.dart +++ b/packages/mix/test/src/attributes/text_style/text_style_dto_test.dart @@ -27,7 +27,6 @@ void main() { decoration: TextDecoration.underline, decorationColor: Colors.blue.toDto(), decorationStyle: TextDecorationStyle.dashed, - locale: const Locale('en', 'US'), height: 2.0, ); @@ -45,7 +44,6 @@ void main() { decoration: TextDecoration.lineThrough, decorationColor: Colors.red.toDto(), decorationStyle: TextDecorationStyle.dotted, - locale: const Locale('en', 'US'), height: 3.0, ); @@ -62,7 +60,6 @@ void main() { expect(merged.letterSpacing, 2.0); expect(merged.wordSpacing, 3.0); expect(merged.height, 3.0); - expect(merged.locale, const Locale('en', 'US')); expect(merged.textBaseline, TextBaseline.alphabetic); }); test('resolve returns correct TextStyle with specific values', () { @@ -80,7 +77,6 @@ void main() { decoration: TextDecoration.underline, decorationColor: Colors.blue.toDto(), decorationStyle: TextDecorationStyle.dashed, - locale: const Locale('en', 'US'), height: 2.0, ); final textStyle = attr.resolve(EmptyMixData); @@ -95,7 +91,6 @@ void main() { expect(textStyle.letterSpacing, 1.0); expect(textStyle.wordSpacing, 2.0); expect(textStyle.height, 2.0); - expect(textStyle.locale, const Locale('en', 'US')); expect(textStyle.textBaseline, TextBaseline.ideographic); return const Placeholder(); diff --git a/packages/mix/test/src/attributes/text_style/text_style_util_test.dart b/packages/mix/test/src/attributes/text_style/text_style_util_test.dart index 89fa81208..677944473 100644 --- a/packages/mix/test/src/attributes/text_style/text_style_util_test.dart +++ b/packages/mix/test/src/attributes/text_style/text_style_util_test.dart @@ -24,7 +24,6 @@ void main() { fontWeight: FontWeight.bold, height: 2.0, letterSpacing: 1.0, - locale: const Locale('en', 'US'), shadows: [ const Shadow( color: Colors.black, @@ -70,7 +69,6 @@ void main() { expect(resolvedValue.fontVariations, [const FontVariation('wght', 900)]); expect(resolvedValue.debugLabel, 'debugLabel'); - expect(resolvedValue.locale, const Locale('en', 'US')); expect(resolvedValue.height, 2.0); expect(resolvedWithPaint.foreground, yellowPaint); expect(resolvedWithPaint.background, purplePaint);