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
03a3457f
Unverified
Commit
03a3457f
authored
Nov 02, 2020
by
David Garcia
Committed by
GitHub
Nov 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(itemExtent): Fix rounded issue using precisionErrorTolerance (#68199)
parent
b7a92f05
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
1 deletion
+95
-1
sliver_fixed_extent_list.dart
...s/flutter/lib/src/rendering/sliver_fixed_extent_list.dart
+13
-1
sliver_fixed_extent_layout_test.dart
...utter/test/rendering/sliver_fixed_extent_layout_test.dart
+82
-0
No files found.
packages/flutter/lib/src/rendering/sliver_fixed_extent_list.dart
View file @
03a3457f
...
...
@@ -85,7 +85,15 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
/// order, without gaps, starting from layout offset zero.
@protected
int
getMaxChildIndexForScrollOffset
(
double
scrollOffset
,
double
itemExtent
)
{
return
itemExtent
>
0.0
?
math
.
max
(
0
,
(
scrollOffset
/
itemExtent
).
ceil
()
-
1
)
:
0
;
if
(
itemExtent
>
0.0
)
{
final
double
actual
=
scrollOffset
/
itemExtent
-
1
;
final
int
round
=
actual
.
round
();
if
(
_isWithinPrecisionErrorTolerance
(
actual
,
round
))
{
return
math
.
max
(
0
,
round
);
}
return
math
.
max
(
0
,
actual
.
ceil
());
}
return
0
;
}
/// Called to estimate the total scrollable extents of this object.
...
...
@@ -350,3 +358,7 @@ class RenderSliverFixedExtentList extends RenderSliverFixedExtentBoxAdaptor {
markNeedsLayout
();
}
}
bool
_isWithinPrecisionErrorTolerance
(
double
actual
,
int
round
)
{
return
(
actual
-
round
).
abs
()
<
precisionErrorTolerance
;
}
packages/flutter/test/rendering/sliver_fixed_extent_layout_test.dart
View file @
03a3457f
...
...
@@ -41,6 +41,74 @@ void main() {
expect
(
children
[
1
].
attached
,
false
);
expect
(
children
[
2
].
attached
,
true
);
});
group
(
'getMaxChildIndexForScrollOffset'
,
()
{
// Regression test for https://github.com/flutter/flutter/issues/68182
const
double
genericItemExtent
=
600.0
;
const
double
extraValueToNotHaveRoundingIssues
=
0.0000001
;
// 6 zeros
const
double
extraValueToHaveRoundingIssues
=
0.00000001
;
// 7 zeros
test
(
'should be 0 when item extent is 0'
,
()
{
const
double
offsetValueWhichDoesntCare
=
1234
;
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
offsetValueWhichDoesntCare
,
0
);
expect
(
actual
,
0
);
});
test
(
'should be 0 when offset is 0'
,
()
{
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
0
,
genericItemExtent
);
expect
(
actual
,
0
);
});
test
(
'should be 0 when offset is equal to item extent'
,
()
{
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
genericItemExtent
,
genericItemExtent
);
expect
(
actual
,
0
);
});
test
(
'should be 1 when offset is greater than item extent'
,
()
{
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
genericItemExtent
+
1
,
genericItemExtent
);
expect
(
actual
,
1
);
});
test
(
'should be 1 when offset is slightly greater than item extent'
,
()
{
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
genericItemExtent
+
extraValueToNotHaveRoundingIssues
,
genericItemExtent
);
expect
(
actual
,
1
);
});
test
(
'should be 4 when offset is four times and a half greater than item extent'
,
()
{
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
genericItemExtent
*
4.5
,
genericItemExtent
);
expect
(
actual
,
4
);
});
test
(
'should be 5 when offset is 6 times greater than item extent'
,
()
{
const
double
anotherGenericItemExtent
=
414.0
;
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
anotherGenericItemExtent
*
6
,
anotherGenericItemExtent
);
expect
(
actual
,
5
);
});
test
(
'should be 5 when offset is 6 times greater than a specific item extent where the division will return more than 13 zero decimals'
,
()
{
const
double
itemExtentSpecificForAProblematicSreenSize
=
411.42857142857144
;
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
itemExtentSpecificForAProblematicSreenSize
*
6
+
extraValueToHaveRoundingIssues
,
itemExtentSpecificForAProblematicSreenSize
);
expect
(
actual
,
5
);
});
test
(
'should be 0 when offset is 0.00000001 times greater than item extent where the divison will return more than 13 zero decimals'
,
()
{
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
genericItemExtent
+
extraValueToHaveRoundingIssues
,
genericItemExtent
);
expect
(
actual
,
0
);
});
});
}
int
testGetMaxChildIndexForScrollOffset
(
double
scrollOffset
,
double
itemExtent
)
{
final
TestRenderSliverFixedExtentBoxAdaptor
renderSliver
=
TestRenderSliverFixedExtentBoxAdaptor
();
return
renderSliver
.
getMaxChildIndexForScrollOffset
(
scrollOffset
,
itemExtent
);
}
class
TestRenderSliverBoxChildManager
extends
RenderSliverBoxChildManager
{
...
...
@@ -103,3 +171,17 @@ class TestRenderSliverBoxChildManager extends RenderSliverBoxChildManager {
@override
void
setDidUnderflow
(
bool
value
)
{
}
}
class
TestRenderSliverFixedExtentBoxAdaptor
extends
RenderSliverFixedExtentBoxAdaptor
{
TestRenderSliverFixedExtentBoxAdaptor
()
:
super
(
childManager:
TestRenderSliverBoxChildManager
(
children:
<
RenderBox
>[]));
@override
// ignore: unnecessary_overrides
int
getMaxChildIndexForScrollOffset
(
double
scrollOffset
,
double
itemExtent
)
{
return
super
.
getMaxChildIndexForScrollOffset
(
scrollOffset
,
itemExtent
);
}
@override
double
get
itemExtent
=>
throw
UnimplementedError
();
}
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