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].

<!-- Links -->
[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
This commit is contained in:
Mairramer 2025-04-24 20:10:07 -03:00 committed by GitHub
parent 83483976ec
commit 71ca6d7e95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 3 deletions

View File

@ -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<strut height normal>',
),
);
if (height != null) {
styles.add(
EnumProperty<TextLeadingDistribution>(
'${prefix}leadingDistribution',
leadingDistribution,
defaultValue: null,
),
);
}
final bool styleSpecified = styles.any(
(DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info),

View File

@ -27,5 +27,16 @@ void main() {
const StrutStyle s5 = StrutStyle(forceStrutHeight: true);
expect(s5.toString(), equals('StrutStyle(<strut height forced>)'));
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)));
});
}