mirror of
https://github.com/flutter/flutter
synced 2024-10-14 04:02:56 +00:00
Capture didExceedMaxLines after doing text layout with constraints (#9457)
Subsequent operations like debugAssertDoesMeetConstraints() may do layout operations that alter _textPainter's state. Fixes https://github.com/flutter/flutter/issues/9372
This commit is contained in:
parent
ab1aa07e8f
commit
a657428b5c
|
@ -6,6 +6,7 @@ import 'dart:ui' as ui;
|
|||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'box.dart';
|
||||
import 'debug.dart';
|
||||
|
@ -189,17 +190,21 @@ class RenderParagraph extends RenderBox {
|
|||
bool _hasVisualOverflow = false;
|
||||
ui.Shader _overflowShader;
|
||||
|
||||
@visibleForTesting
|
||||
bool get debugHasOverflowShader => _overflowShader != null;
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
_layoutTextWithConstraints(constraints);
|
||||
// We grab _textPainter.size here because assigning to `size` will trigger
|
||||
// us to validate our intrinsic sizes, which will change _textPainter's
|
||||
// layout because the intrinsic size calculations are destructive.
|
||||
// Other _textPainter state like didExceedMaxLines will also be affected.
|
||||
final Size textSize = _textPainter.size;
|
||||
final bool didOverflowHeight = _textPainter.didExceedMaxLines;
|
||||
size = constraints.constrain(textSize);
|
||||
|
||||
final bool didOverflowWidth = size.width < textSize.width;
|
||||
final bool didOverflowHeight = _textPainter.didExceedMaxLines;
|
||||
// TODO(abarth): We're only measuring the sizes of the line boxes here. If
|
||||
// the glyphs draw outside the line boxes, we might think that there isn't
|
||||
// visual overflow when there actually is visual overflow. This can become
|
||||
|
|
|
@ -135,5 +135,13 @@ void main() {
|
|||
|
||||
relayoutWith(maxLines: null, softWrap: false, overflow: TextOverflow.ellipsis);
|
||||
expect(paragraph.size.height, equals(2 * lineHeight));
|
||||
|
||||
// Test presence of the fade effect.
|
||||
relayoutWith(maxLines: 3, softWrap: true, overflow: TextOverflow.fade);
|
||||
expect(paragraph.debugHasOverflowShader, isTrue);
|
||||
|
||||
relayoutWith(maxLines: 100, softWrap: true, overflow: TextOverflow.fade);
|
||||
expect(paragraph.debugHasOverflowShader, isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue