Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
3bc3ea51
Unverified
Commit
3bc3ea51
authored
Aug 04, 2020
by
LongCatIsLooong
Committed by
GitHub
Aug 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
longestLine layout width (#62657)
parent
f29f05ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletion
+47
-1
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+15
-1
text_test.dart
packages/flutter/test/widgets/text_test.dart
+32
-0
No files found.
packages/flutter/lib/src/painting/text_painter.dart
View file @
3bc3ea51
...
...
@@ -568,7 +568,21 @@ class TextPainter {
_previousCaretPrototype
=
null
;
_paragraph
.
layout
(
ui
.
ParagraphConstraints
(
width:
maxWidth
));
if
(
minWidth
!=
maxWidth
)
{
final
double
newWidth
=
maxIntrinsicWidth
.
clamp
(
minWidth
,
maxWidth
)
as
double
;
double
newWidth
;
switch
(
textWidthBasis
)
{
case
TextWidthBasis
.
longestLine
:
// The parent widget expects the paragraph to be exactly
// `TextPainter.width` wide, if that value satisfies the constraints
// it gave to the TextPainter. So when `textWidthBasis` is longestLine,
// the paragraph's width needs to be as close to the width of its
// longest line as possible.
newWidth
=
_applyFloatingPointHack
(
_paragraph
.
longestLine
);
break
;
case
TextWidthBasis
.
parent
:
newWidth
=
maxIntrinsicWidth
;
break
;
}
newWidth
=
newWidth
.
clamp
(
minWidth
,
maxWidth
)
as
double
;
if
(
newWidth
!=
_applyFloatingPointHack
(
_paragraph
.
width
))
{
_paragraph
.
layout
(
ui
.
ParagraphConstraints
(
width:
newWidth
));
}
...
...
packages/flutter/test/widgets/text_test.dart
View file @
3bc3ea51
...
...
@@ -914,6 +914,38 @@ void main() {
expect
(
tester
.
getSize
(
find
.
text
(
'RIGHT ALIGNED, LONGEST LINE'
)).
width
,
equals
(
width
));
},
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/44020
testWidgets
(
'textWidthBasis.longestLine confines the width of the paragraph '
'when given loose constraints'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/62550.
await
tester
.
pumpWidget
(
Center
(
child:
SizedBox
(
width:
400
,
child:
Center
(
child:
RichText
(
text:
const
TextSpan
(
text:
'fwefwefwewfefewfwe fwfwfwefweabcdefghijklmnopqrstuvwxyz'
),
textWidthBasis:
TextWidthBasis
.
longestLine
,
textDirection:
TextDirection
.
ltr
,
),
),
),
),
);
expect
(
find
.
byType
(
RichText
),
paints
..
something
((
Symbol
method
,
List
<
dynamic
>
arguments
)
{
if
(
method
!=
#drawParagraph
)
return
false
;
final
ui
.
Paragraph
paragraph
=
arguments
[
0
]
as
ui
.
Paragraph
;
if
(
paragraph
.
width
>
paragraph
.
longestLine
)
throw
'paragraph width (
${paragraph.width}
) greater than its longest line (
${paragraph.longestLine}
).'
;
if
(
paragraph
.
width
>=
400
)
throw
'paragraph.width (
${paragraph.width}
) >= 400'
;
return
true
;
}));
},
skip:
isBrowser
);
// 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'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment