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
c746be66
Unverified
Commit
c746be66
authored
Dec 21, 2021
by
nt4f04uNd
Committed by
GitHub
Dec 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix precision error in RenderSliverFixedExtentBoxAdaptor assertion (#95598)
parent
5c853229
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
10 deletions
+33
-10
sliver_fixed_extent_list.dart
...s/flutter/lib/src/rendering/sliver_fixed_extent_list.dart
+2
-6
sliver_fixed_extent_layout_test.dart
...utter/test/rendering/sliver_fixed_extent_layout_test.dart
+4
-4
page_view_test.dart
packages/flutter/test/widgets/page_view_test.dart
+27
-0
No files found.
packages/flutter/lib/src/rendering/sliver_fixed_extent_list.dart
View file @
c746be66
...
...
@@ -68,7 +68,7 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
if
(
itemExtent
>
0.0
)
{
final
double
actual
=
scrollOffset
/
itemExtent
;
final
int
round
=
actual
.
round
();
if
((
actual
-
round
).
abs
()
<
precisionErrorTolerance
)
{
if
((
actual
*
itemExtent
-
round
*
itemExtent
).
abs
()
<
precisionErrorTolerance
)
{
return
round
;
}
return
actual
.
floor
();
...
...
@@ -88,7 +88,7 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
if
(
itemExtent
>
0.0
)
{
final
double
actual
=
scrollOffset
/
itemExtent
-
1
;
final
int
round
=
actual
.
round
();
if
(
_isWithinPrecisionErrorTolerance
(
actual
,
round
)
)
{
if
(
(
actual
*
itemExtent
-
round
*
itemExtent
).
abs
()
<
precisionErrorTolerance
)
{
return
math
.
max
(
0
,
round
);
}
return
math
.
max
(
0
,
actual
.
ceil
());
...
...
@@ -358,7 +358,3 @@ 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 @
c746be66
...
...
@@ -45,8 +45,8 @@ void main() {
// 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
const
double
extraValueToNotHaveRoundingIssues
=
1
e
-
10
;
const
double
extraValueToHaveRoundingIssues
=
1
e
-
11
;
test
(
'should be 0 when item extent is 0'
,
()
{
const
double
offsetValueWhichDoesntCare
=
1234
;
...
...
@@ -91,7 +91,7 @@ void main() {
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'
,
()
{
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
itemExtentSpecificForAProblematicScreenSize
=
411.42857142857144
;
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
itemExtentSpecificForAProblematicScreenSize
*
6
+
extraValueToHaveRoundingIssues
,
...
...
@@ -100,7 +100,7 @@ void main() {
expect
(
actual
,
5
);
});
test
(
'should be 0
when offset is 0.00000001 times greater than item extent where the division will return more than 13 zero decimals
'
,
()
{
test
(
'should be 0
when offset is a bit greater than item extent
'
,
()
{
final
int
actual
=
testGetMaxChildIndexForScrollOffset
(
genericItemExtent
+
extraValueToHaveRoundingIssues
,
genericItemExtent
,
...
...
packages/flutter/test/widgets/page_view_test.dart
View file @
c746be66
...
...
@@ -1096,4 +1096,31 @@ void main() {
expect
(
tester
.
widget
<
SliverFillViewport
>(
viewportFinder
()).
padEnds
,
false
);
});
testWidgets
(
'PageView - precision error inside RenderSliverFixedExtentBoxAdaptor'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/95101
final
PageController
controller
=
PageController
(
initialPage:
152
);
await
tester
.
pumpWidget
(
Center
(
child:
SizedBox
(
width:
392.72727272727275
,
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
PageView
.
builder
(
controller:
controller
,
itemCount:
366
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
const
SizedBox
();
},
),
),
),
),
);
controller
.
jumpToPage
(
365
);
await
tester
.
pump
();
expect
(
tester
.
takeException
(),
isNull
);
});
}
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