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))); }); }