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
00d95e62
Unverified
Commit
00d95e62
authored
Jun 18, 2019
by
chunhtai
Committed by
GitHub
Jun 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix page scroll position rounding error (#34519)
parent
5c52498d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
page_view.dart
packages/flutter/lib/src/widgets/page_view.dart
+14
-2
page_view_test.dart
packages/flutter/test/widgets/page_view_test.dart
+20
-0
No files found.
packages/flutter/lib/src/widgets/page_view.dart
View file @
00d95e62
...
...
@@ -8,6 +8,7 @@ import 'dart:math' as math;
import
'package:flutter/physics.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/gestures.dart'
show
DragStartBehavior
;
import
'package:flutter/foundation.dart'
show
precisionErrorTolerance
;
import
'basic.dart'
;
import
'debug.dart'
;
...
...
@@ -368,7 +369,12 @@ class _PagePosition extends ScrollPositionWithSingleContext implements PageMetri
}
double
getPageFromPixels
(
double
pixels
,
double
viewportDimension
)
{
return
math
.
max
(
0.0
,
pixels
)
/
math
.
max
(
1.0
,
viewportDimension
*
viewportFraction
);
final
double
actual
=
math
.
max
(
0.0
,
pixels
)
/
math
.
max
(
1.0
,
viewportDimension
*
viewportFraction
);
final
double
round
=
actual
.
roundToDouble
();
if
((
actual
-
round
).
abs
()
<
precisionErrorTolerance
)
{
return
round
;
}
return
actual
;
}
double
getPixelsFromPage
(
double
page
)
{
...
...
@@ -376,7 +382,13 @@ class _PagePosition extends ScrollPositionWithSingleContext implements PageMetri
}
@override
double
get
page
=>
pixels
==
null
?
null
:
getPageFromPixels
(
pixels
.
clamp
(
minScrollExtent
,
maxScrollExtent
),
viewportDimension
);
double
get
page
{
assert
(
pixels
==
null
||
(
minScrollExtent
!=
null
&&
maxScrollExtent
!=
null
),
'Page value is only available after content dimensions are established.'
,
);
return
pixels
==
null
?
null
:
getPageFromPixels
(
pixels
.
clamp
(
minScrollExtent
,
maxScrollExtent
),
viewportDimension
);
}
@override
void
saveScrollOffset
()
{
...
...
packages/flutter/test/widgets/page_view_test.dart
View file @
00d95e62
...
...
@@ -728,4 +728,24 @@ void main() {
);
expect
(
page2
.
page
,
4.0
);
});
testWidgets
(
'Page controller can handle rounding issue'
,
(
WidgetTester
tester
)
async
{
final
PageController
pageController
=
PageController
();
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
PageView
(
controller:
pageController
,
children:
List
<
Widget
>.
generate
(
3
,
(
int
i
)
{
return
Semantics
(
child:
Text
(
'Page #
$i
'
),
container:
true
,
);
}),
),
));
// Simulate precision error.
pageController
.
position
.
jumpTo
(
799.99999999999
);
expect
(
pageController
.
page
,
1
);
});
}
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