From 71ca6d7e95d5bce880f1804f7e5acc8c82349d64 Mon Sep 17 00:00:00 2001 From: Mairramer <50643541+Mairramer@users.noreply.github.com> Date: Thu, 24 Apr 2025 20:10:07 -0300 Subject: [PATCH] Adds leadingDistribution to equality checker in StrutStyle (#164813) Fixes #164811 Adds `leadingDistribution` to equality checker. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --- .../flutter/lib/src/painting/strut_style.dart | 22 ++++++++++++++++--- .../test/painting/strut_style_test.dart | 11 ++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/painting/strut_style.dart b/packages/flutter/lib/src/painting/strut_style.dart index 76497151c9d..58184f0d749 100644 --- a/packages/flutter/lib/src/painting/strut_style.dart +++ b/packages/flutter/lib/src/painting/strut_style.dart @@ -528,7 +528,8 @@ class StrutStyle with Diagnosticable { height != other.height || leading != other.leading || forceStrutHeight != other.forceStrutHeight || - !listEquals(fontFamilyFallback, other.fontFamilyFallback)) { + (!listEquals(fontFamilyFallback, other.fontFamilyFallback)) || + (height != null && leadingDistribution != other.leadingDistribution)) { return RenderComparison.layout; } return RenderComparison.identical; @@ -547,16 +548,20 @@ class StrutStyle with Diagnosticable { return this; } + final double? effectiveHeight = height ?? other.height; + return StrutStyle( fontFamily: fontFamily ?? other.fontFamily, fontFamilyFallback: fontFamilyFallback ?? other.fontFamilyFallback, fontSize: fontSize ?? other.fontSize, - height: height ?? other.height, + height: effectiveHeight, leading: leading, // No equivalent property in TextStyle yet. fontWeight: fontWeight ?? other.fontWeight, fontStyle: fontStyle ?? other.fontStyle, forceStrutHeight: forceStrutHeight, // StrutStyle-unique property. debugLabel: debugLabel ?? other.debugLabel, + leadingDistribution: + effectiveHeight != null ? (leadingDistribution ?? other.leadingDistribution) : null, // Package is embedded within the getters for fontFamilyFallback. ); } @@ -576,7 +581,9 @@ class StrutStyle with Diagnosticable { other.fontStyle == fontStyle && other.height == height && other.leading == leading && - other.forceStrutHeight == forceStrutHeight; + other.forceStrutHeight == forceStrutHeight && + (height == null || leadingDistribution == other.leadingDistribution) && + listEquals(other.fontFamilyFallback, fontFamilyFallback); } @override @@ -623,6 +630,15 @@ class StrutStyle with Diagnosticable { ifFalse: '$prefix', ), ); + if (height != null) { + styles.add( + EnumProperty( + '${prefix}leadingDistribution', + leadingDistribution, + defaultValue: null, + ), + ); + } final bool styleSpecified = styles.any( (DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info), diff --git a/packages/flutter/test/painting/strut_style_test.dart b/packages/flutter/test/painting/strut_style_test.dart index 3c1591ede77..355c8c704e4 100644 --- a/packages/flutter/test/painting/strut_style_test.dart +++ b/packages/flutter/test/painting/strut_style_test.dart @@ -27,5 +27,16 @@ void main() { const StrutStyle s5 = StrutStyle(forceStrutHeight: true); expect(s5.toString(), equals('StrutStyle()')); + + const StrutStyle s6 = StrutStyle(height: 14, leadingDistribution: TextLeadingDistribution.even); + expect(s6.toString(), equals('StrutStyle(height: 14.0x, leadingDistribution: even)')); + + const StrutStyle s7 = StrutStyle( + height: 14, + leadingDistribution: TextLeadingDistribution.proportional, + ); + expect(s7.toString(), equals('StrutStyle(height: 14.0x, leadingDistribution: proportional)')); + + expect(s6, isNot(equals(s7))); }); }