diff --git a/packages/flutter/lib/painting.dart b/packages/flutter/lib/painting.dart index 2fa89c23cf8b..b5d55b5b89bb 100644 --- a/packages/flutter/lib/painting.dart +++ b/packages/flutter/lib/painting.dart @@ -17,7 +17,7 @@ /// painting boxes. library painting; -export 'dart:ui' show PlaceholderAlignment, Shadow, TextHeightBehavior, TextLeadingDistribution; +export 'dart:ui' show PlaceholderAlignment, Shadow, TextHeightBehavior, TextLeadingDistribution, kTextHeightNone; export 'src/painting/alignment.dart'; export 'src/painting/basic_types.dart'; diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index 24de4a5bb4e7..e03ea5b736af 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -8,6 +8,7 @@ import 'dart:ui' as ui show Shadow, StrutStyle, TextStyle, + kTextHeightNone, lerpDouble; import 'package:flutter/foundation.dart'; @@ -640,14 +641,13 @@ class TextStyle with Diagnosticable { /// The height of this text span, as a multiple of the font size. /// - /// When [height] is null or omitted, the line height will be determined - /// by the font's metrics directly, which may differ from the fontSize. - /// When [height] is non-null, the line height of the span of text will be a - /// multiple of [fontSize] and be exactly `fontSize * height` logical pixels - /// tall. + /// When [height] is [kTextHeightNone], the line height will be determined by + /// the font's metrics directly, which may differ from the fontSize. Otherwise + /// the line height of the span of text will be a multiple of [fontSize], + /// and be exactly `fontSize * height` logical pixels tall. /// - /// For most fonts, setting [height] to 1.0 is not the same as omitting or - /// setting height to null because the [fontSize] sets the height of the EM-square, + /// For most fonts, setting [height] to 1.0 is not the same as setting height + /// to [kTextHeightNone] because the [fontSize] sets the height of the EM-square, /// which is different than the font provided metrics for line height. The /// following diagram illustrates the difference between the font-metrics /// defined line height and the line height produced with `height: 1.0` @@ -954,7 +954,8 @@ class TextStyle with Diagnosticable { /// [TextStyle] with a [FontWeight.w300]. /// /// If the underlying values are null, then the corresponding factors and/or - /// deltas must not be specified. + /// deltas must not be specified. Additionally, if [height] is [kTextHeightNone] + /// it will not be modified by this method. /// /// If [foreground] is specified on this object, then applying [color] here /// will have no effect and if [background] is specified on this object, then @@ -1014,7 +1015,7 @@ class TextStyle with Diagnosticable { letterSpacing: letterSpacing == null ? null : letterSpacing! * letterSpacingFactor + letterSpacingDelta, wordSpacing: wordSpacing == null ? null : wordSpacing! * wordSpacingFactor + wordSpacingDelta, textBaseline: textBaseline ?? this.textBaseline, - height: height == null ? null : height! * heightFactor + heightDelta, + height: (height == null || height == ui.kTextHeightNone) ? height : height! * heightFactor + heightDelta, leadingDistribution: leadingDistribution ?? this.leadingDistribution, locale: locale ?? this.locale, foreground: foreground, diff --git a/packages/flutter/test/painting/text_painter_test.dart b/packages/flutter/test/painting/text_painter_test.dart index 73be30b406f7..8534f5297b21 100644 --- a/packages/flutter/test/painting/text_painter_test.dart +++ b/packages/flutter/test/painting/text_painter_test.dart @@ -1696,6 +1696,17 @@ void main() { ); }); + test('kTextHeightNone unsets the text height multiplier', () { + final TextPainter painter = TextPainter( + textDirection: TextDirection.ltr, + text: const TextSpan( + style: TextStyle(fontSize: 10, height: 1000), + children: [TextSpan(text: 'A', style: TextStyle(height: kTextHeightNone))], + ), + )..layout(); + expect(painter.height, 10); + }); + test('TextPainter dispatches memory events', () async { await expectLater( await memoryEvents(() => TextPainter().dispose(), TextPainter), diff --git a/packages/flutter/test/painting/text_style_test.dart b/packages/flutter/test/painting/text_style_test.dart index 7ab22410888f..f44250d5ae7f 100644 --- a/packages/flutter/test/painting/text_style_test.dart +++ b/packages/flutter/test/painting/text_style_test.dart @@ -570,6 +570,11 @@ void main() { style.apply(leadingDistribution: TextLeadingDistribution.proportional).leadingDistribution, TextLeadingDistribution.proportional, ); + + expect( + const TextStyle(height: kTextHeightNone).apply(heightFactor: 1000, heightDelta: 1000).height, + kTextHeightNone, + ); }); test('TextStyle fontFamily and package', () {