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
1b57006c
Commit
1b57006c
authored
Jul 24, 2019
by
K. P. Sroka
Committed by
Dan Field
Jul 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevents infinite loop in Table._computeColumnWidths (#36262)
parent
9946f7cf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
22 deletions
+74
-22
table.dart
packages/flutter/lib/src/rendering/table.dart
+18
-22
table_test.dart
packages/flutter/test/rendering/table_test.dart
+26
-0
table_test.dart
packages/flutter/test/widgets/table_test.dart
+30
-0
No files found.
packages/flutter/lib/src/rendering/table.dart
View file @
1b57006c
...
...
@@ -918,10 +918,7 @@ class RenderTable extends RenderBox {
// columns shrinking them proportionally until we have no
// available columns, then do the same to the non-flexible ones.
int
availableColumns
=
columns
;
// Handle double precision errors which causes this loop to become
// stuck in certain configurations.
const
double
minimumDeficit
=
precisionErrorTolerance
;
while
(
deficit
>
minimumDeficit
&&
totalFlex
>
minimumDeficit
)
{
while
(
deficit
>
precisionErrorTolerance
&&
totalFlex
>
precisionErrorTolerance
)
{
double
newTotalFlex
=
0.0
;
for
(
int
x
=
0
;
x
<
columns
;
x
+=
1
)
{
if
(
flexes
[
x
]
!=
null
)
{
...
...
@@ -943,14 +940,14 @@ class RenderTable extends RenderBox {
}
totalFlex
=
newTotalFlex
;
}
if
(
deficit
>
0.
0
)
{
while
(
deficit
>
precisionErrorTolerance
&&
availableColumns
>
0
)
{
// Now we have to take out the remaining space from the
// columns that aren't minimum sized.
// To make this fair, we repeatedly remove equal amounts from
// each column, clamped to the minimum width, until we run out
// of columns that aren't at their minWidth.
do
{
final
double
delta
=
deficit
/
availableColumns
;
assert
(
delta
!=
0
);
int
newAvailableColumns
=
0
;
for
(
int
x
=
0
;
x
<
columns
;
x
+=
1
)
{
final
double
availableDelta
=
widths
[
x
]
-
minWidths
[
x
];
...
...
@@ -967,7 +964,6 @@ class RenderTable extends RenderBox {
}
}
availableColumns
=
newAvailableColumns
;
}
while
(
deficit
>
0.0
&&
availableColumns
>
0
);
}
}
return
widths
;
...
...
packages/flutter/test/rendering/table_test.dart
View file @
1b57006c
...
...
@@ -217,4 +217,30 @@ void main() {
pumpFrame
();
expect
(
table
,
paints
..
path
()..
path
()..
path
()..
path
()..
path
()..
path
());
});
test
(
'Table flex sizing'
,
()
{
const
BoxConstraints
cellConstraints
=
BoxConstraints
.
tightFor
(
width:
100
,
height:
100
);
final
RenderTable
table
=
RenderTable
(
textDirection:
TextDirection
.
rtl
,
children:
<
List
<
RenderBox
>>[
List
<
RenderBox
>.
generate
(
7
,
(
int
_
)
=>
RenderConstrainedBox
(
additionalConstraints:
cellConstraints
),
),
],
columnWidths:
const
<
int
,
TableColumnWidth
>{
0
:
FlexColumnWidth
(
1.0
),
1
:
FlexColumnWidth
(
0.123
),
2
:
FlexColumnWidth
(
0.123
),
3
:
FlexColumnWidth
(
0.123
),
4
:
FlexColumnWidth
(
0.123
),
5
:
FlexColumnWidth
(
0.123
),
6
:
FlexColumnWidth
(
0.123
),
},
);
layout
(
table
,
constraints:
BoxConstraints
.
tight
(
const
Size
(
800.0
,
600.0
)));
expect
(
table
.
hasSize
,
true
);
});
}
packages/flutter/test/widgets/table_test.dart
View file @
1b57006c
...
...
@@ -376,6 +376,36 @@ void main() {
// If the above bug is present this test will never terminate.
});
testWidgets
(
'Calculating flex columns with small width deficit'
,
(
WidgetTester
tester
)
async
{
const
SizedBox
cell
=
SizedBox
(
width:
1
,
height:
1
);
// If the error is present, pumpWidget() will fail due to an unsatisfied
// assertion during the layout phase.
await
tester
.
pumpWidget
(
ConstrainedBox
(
constraints:
BoxConstraints
.
tight
(
const
Size
(
600
,
800
)),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Table
(
columnWidths:
const
<
int
,
TableColumnWidth
>{
0
:
FlexColumnWidth
(
1.0
),
1
:
FlexColumnWidth
(
0.123
),
2
:
FlexColumnWidth
(
0.123
),
3
:
FlexColumnWidth
(
0.123
),
4
:
FlexColumnWidth
(
0.123
),
5
:
FlexColumnWidth
(
0.123
),
6
:
FlexColumnWidth
(
0.123
),
},
children:
<
TableRow
>[
TableRow
(
children:
List
<
Widget
>.
filled
(
7
,
cell
)),
TableRow
(
children:
List
<
Widget
>.
filled
(
7
,
cell
)),
],
),
),
),
);
expect
(
tester
.
takeException
(),
null
);
});
testWidgets
(
'Table widget - repump test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
...
...
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