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
b5a4d089
Unverified
Commit
b5a4d089
authored
Nov 12, 2020
by
Michael Goderbauer
Committed by
GitHub
Nov 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Intrinsic Width fixes for RenderParagraph (#70236)
parent
3fce16c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
15 deletions
+51
-15
paragraph.dart
packages/flutter/lib/src/rendering/paragraph.dart
+9
-15
text_test.dart
packages/flutter/test/widgets/text_test.dart
+42
-0
No files found.
packages/flutter/lib/src/rendering/paragraph.dart
View file @
b5a4d089
...
...
@@ -395,42 +395,36 @@ class RenderParagraph extends RenderBox
RenderBox
?
child
=
firstChild
;
final
List
<
PlaceholderDimensions
>
placeholderDimensions
=
List
<
PlaceholderDimensions
>.
filled
(
childCount
,
PlaceholderDimensions
.
empty
,
growable:
false
);
int
childIndex
=
0
;
// Takes textScaleFactor into account because the content of the placeholder
// span will be scale up when it paints.
height
=
height
/
textScaleFactor
;
while
(
child
!=
null
)
{
// Height and baseline is irrelevant as all text will be laid
// out in a single line.
// out in a single line.
Therefore, using 0.0 as a dummy for the height.
placeholderDimensions
[
childIndex
]
=
PlaceholderDimensions
(
size:
Size
(
child
.
getMaxIntrinsicWidth
(
height
),
height
),
size:
Size
(
child
.
getMaxIntrinsicWidth
(
double
.
infinity
),
0.0
),
alignment:
_placeholderSpans
[
childIndex
].
alignment
,
baseline:
_placeholderSpans
[
childIndex
].
baseline
,
);
child
=
childAfter
(
child
);
childIndex
+=
1
;
}
_textPainter
.
setPlaceholderDimensions
(
placeholderDimensions
.
cast
<
PlaceholderDimensions
>()
);
_textPainter
.
setPlaceholderDimensions
(
placeholderDimensions
);
}
void
_computeChildrenWidthWithMinIntrinsics
(
double
height
)
{
RenderBox
?
child
=
firstChild
;
final
List
<
PlaceholderDimensions
>
placeholderDimensions
=
List
<
PlaceholderDimensions
>.
filled
(
childCount
,
PlaceholderDimensions
.
empty
,
growable:
false
);
int
childIndex
=
0
;
// Takes textScaleFactor into account because the content of the placeholder
// span will be scale up when it paints.
height
=
height
/
textScaleFactor
;
while
(
child
!=
null
)
{
final
double
intrinsicWidth
=
child
.
getMinIntrinsicWidth
(
height
);
final
double
intrinsicHeight
=
child
.
getMinIntrinsicHeight
(
intrinsicWidth
);
// Height and baseline is irrelevant; only looking for the widest word or
// placeholder. Therefore, using 0.0 as a dummy for height.
placeholderDimensions
[
childIndex
]
=
PlaceholderDimensions
(
size:
Size
(
intrinsicWidth
,
intrinsicHeight
),
size:
Size
(
child
.
getMinIntrinsicWidth
(
double
.
infinity
),
0.0
),
alignment:
_placeholderSpans
[
childIndex
].
alignment
,
baseline:
_placeholderSpans
[
childIndex
].
baseline
,
);
child
=
childAfter
(
child
);
childIndex
+=
1
;
}
_textPainter
.
setPlaceholderDimensions
(
placeholderDimensions
.
cast
<
PlaceholderDimensions
>()
);
_textPainter
.
setPlaceholderDimensions
(
placeholderDimensions
);
}
void
_computeChildrenHeightWithMinIntrinsics
(
double
width
)
{
...
...
@@ -451,7 +445,7 @@ class RenderParagraph extends RenderBox
child
=
childAfter
(
child
);
childIndex
+=
1
;
}
_textPainter
.
setPlaceholderDimensions
(
placeholderDimensions
.
cast
<
PlaceholderDimensions
>()
);
_textPainter
.
setPlaceholderDimensions
(
placeholderDimensions
);
}
@override
...
...
@@ -593,7 +587,7 @@ class RenderParagraph extends RenderBox
child
=
childAfter
(
child
);
childIndex
+=
1
;
}
_placeholderDimensions
=
placeholderDimensions
.
cast
<
PlaceholderDimensions
>()
;
_placeholderDimensions
=
placeholderDimensions
;
}
// Iterate through the laid-out children and set the parentData offsets based
...
...
packages/flutter/test/widgets/text_test.dart
View file @
b5a4d089
...
...
@@ -4,6 +4,7 @@
import
'dart:ui'
as
ui
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
...
...
@@ -1209,6 +1210,47 @@ void main() {
ignoreTransform:
true
,
));
},
semanticsEnabled:
true
,
skip:
isBrowser
);
// Browser does not support widget span
testWidgets
(
'RenderParagraph intrinsic width'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
Container
(
height:
100
,
child:
IntrinsicWidth
(
child:
RichText
(
text:
TextSpan
(
style:
const
TextStyle
(
fontSize:
16
,
height:
1
),
children:
<
InlineSpan
>[
const
TextSpan
(
text:
'S '
),
WidgetSpan
(
alignment:
PlaceholderAlignment
.
top
,
child:
Wrap
(
direction:
Axis
.
vertical
,
children:
<
Widget
>[
Container
(
width:
200
,
height:
100
),
Container
(
width:
200
,
height:
30
),
],
),
),
const
TextSpan
(
text:
' E'
),
],
),
),
),
),
),
),
);
expect
(
tester
.
getSize
(
find
.
byType
(
RichText
)).
width
,
200
+
4
*
16.0
);
final
RenderParagraph
paragraph
=
tester
.
renderObject
<
RenderParagraph
>(
find
.
byType
(
RichText
));
// The inline spans are rendered on one (horizontal) line, the sum of the widths is the max intrinsic width.
expect
(
paragraph
.
getMaxIntrinsicWidth
(
0.0
),
200
+
4
*
16.0
);
// The inline spans are rendered in one vertical run, the widest one determines the min intrinsic width.
expect
(
paragraph
.
getMinIntrinsicWidth
(
0.0
),
200
,
skip:
'https://github.com/flutter/flutter/issues/70230'
);
});
}
Future
<
void
>
_pumpTextWidget
({
...
...
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