Fix right alignment TWB longestLine (#54234)
Fixes an alignment bug seen when using both TextWidthBasis.longestLine and TextAlign.right.
This commit is contained in:
committed by
GitHub
parent
0b9c42f944
commit
6c70a8fef6
@@ -564,7 +564,7 @@ class TextPainter {
|
||||
_paragraph.layout(ui.ParagraphConstraints(width: maxWidth));
|
||||
if (minWidth != maxWidth) {
|
||||
final double newWidth = maxIntrinsicWidth.clamp(minWidth, maxWidth) as double;
|
||||
if (newWidth != width) {
|
||||
if (newWidth != _applyFloatingPointHack(_paragraph.width)) {
|
||||
_paragraph.layout(ui.ParagraphConstraints(width: newWidth));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -800,6 +800,56 @@ void main() {
|
||||
expect(textSizeLongestLine.height, equals(fontHeight * 2));
|
||||
}, skip: isBrowser); // TODO(yjbanov): https://github.com/flutter/flutter/issues/44020
|
||||
|
||||
testWidgets('textWidthBasis with textAlign still obeys parent alignment', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const <Widget>[
|
||||
Text(
|
||||
'LEFT ALIGNED, PARENT',
|
||||
textAlign: TextAlign.left,
|
||||
textWidthBasis: TextWidthBasis.parent,
|
||||
),
|
||||
Text(
|
||||
'RIGHT ALIGNED, PARENT',
|
||||
textAlign: TextAlign.right,
|
||||
textWidthBasis: TextWidthBasis.parent,
|
||||
),
|
||||
Text(
|
||||
'LEFT ALIGNED, LONGEST LINE',
|
||||
textAlign: TextAlign.left,
|
||||
textWidthBasis: TextWidthBasis.longestLine,
|
||||
),
|
||||
Text(
|
||||
'RIGHT ALIGNED, LONGEST LINE',
|
||||
textAlign: TextAlign.right,
|
||||
textWidthBasis: TextWidthBasis.longestLine,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// All Texts have the same horizontal alignment.
|
||||
final double offsetX = tester.getTopLeft(find.text('LEFT ALIGNED, PARENT')).dx;
|
||||
expect(tester.getTopLeft(find.text('RIGHT ALIGNED, PARENT')).dx, equals(offsetX));
|
||||
expect(tester.getTopLeft(find.text('LEFT ALIGNED, LONGEST LINE')).dx, equals(offsetX));
|
||||
expect(tester.getTopLeft(find.text('RIGHT ALIGNED, LONGEST LINE')).dx, equals(offsetX));
|
||||
|
||||
// All Texts are less than or equal to the width of the Column.
|
||||
final double width = tester.getSize(find.byType(Column)).width;
|
||||
expect(tester.getSize(find.text('LEFT ALIGNED, PARENT')).width, lessThan(width));
|
||||
expect(tester.getSize(find.text('RIGHT ALIGNED, PARENT')).width, lessThan(width));
|
||||
expect(tester.getSize(find.text('LEFT ALIGNED, LONGEST LINE')).width, lessThan(width));
|
||||
expect(tester.getSize(find.text('RIGHT ALIGNED, LONGEST LINE')).width, equals(width));
|
||||
}, skip: isBrowser); // TODO(yjbanov): https://github.com/flutter/flutter/issues/44020
|
||||
|
||||
testWidgets('Paragraph.getBoxesForRange returns nothing when selection range is zero length', (WidgetTester tester) async {
|
||||
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle());
|
||||
builder.addText('hello');
|
||||
|
||||
Reference in New Issue
Block a user