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
f4f68dff
Commit
f4f68dff
authored
May 09, 2017
by
Ian Hickson
Committed by
GitHub
May 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the page-view remembering logic actually work. (#9905)
It wasn't tested, which is why it didn't work before.
parent
3bd2ecb2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
3 deletions
+68
-3
page_view.dart
packages/flutter/lib/src/widgets/page_view.dart
+6
-3
scroll_position.dart
packages/flutter/lib/src/widgets/scroll_position.dart
+3
-0
page_view_test.dart
packages/flutter/test/widgets/page_view_test.dart
+59
-0
No files found.
packages/flutter/lib/src/widgets/page_view.dart
View file @
f4f68dff
...
...
@@ -154,7 +154,9 @@ class _PagePosition extends ScrollPositionWithSingleContext {
this
.
initialPage
:
0
,
double
viewportFraction:
1.0
,
ScrollPosition
oldPosition
,
})
:
_viewportFraction
=
viewportFraction
,
super
(
})
:
_viewportFraction
=
viewportFraction
,
_pageToUseOnStartup
=
initialPage
.
toDouble
(),
super
(
physics:
physics
,
context:
context
,
initialPixels:
null
,
...
...
@@ -166,6 +168,7 @@ class _PagePosition extends ScrollPositionWithSingleContext {
}
final
int
initialPage
;
double
_pageToUseOnStartup
;
double
get
viewportFraction
=>
_viewportFraction
;
double
_viewportFraction
;
...
...
@@ -198,7 +201,7 @@ class _PagePosition extends ScrollPositionWithSingleContext {
if
(
pixels
==
null
)
{
final
double
value
=
PageStorage
.
of
(
context
.
storageContext
)?.
readState
(
context
.
storageContext
);
if
(
value
!=
null
)
correctPixels
(
getPixelsFromPage
(
value
))
;
_pageToUseOnStartup
=
value
;
}
}
...
...
@@ -207,7 +210,7 @@ class _PagePosition extends ScrollPositionWithSingleContext {
final
double
oldViewportDimensions
=
this
.
viewportDimension
;
final
bool
result
=
super
.
applyViewportDimension
(
viewportDimension
);
final
double
oldPixels
=
pixels
;
final
double
page
=
(
oldPixels
==
null
||
oldViewportDimensions
==
0.0
)
?
initialPage
.
toDouble
()
:
getPageFromPixels
(
oldPixels
,
oldViewportDimensions
);
final
double
page
=
(
oldPixels
==
null
||
oldViewportDimensions
==
0.0
)
?
_pageToUseOnStartup
:
getPageFromPixels
(
oldPixels
,
oldViewportDimensions
);
final
double
newPixels
=
getPixelsFromPage
(
page
);
if
(
newPixels
!=
oldPixels
)
{
correctPixels
(
newPixels
);
...
...
packages/flutter/lib/src/widgets/scroll_position.dart
View file @
f4f68dff
...
...
@@ -300,6 +300,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
/// The default implementation reads the value from the nearest [PageStorage]
/// found from the [context]'s [ScrollContext.storageContext] property, and
/// sets it using [correctPixels], if [pixels] is still null.
///
/// This method is called from the constructor, so layout has not yet
/// occurred, and the viewport dimensions aren't yet known when it is called.
@protected
void
restoreScrollOffset
()
{
if
(
pixels
==
null
)
{
...
...
packages/flutter/test/widgets/page_view_test.dart
View file @
f4f68dff
...
...
@@ -398,4 +398,63 @@ void main() {
await
tester
.
pump
();
expect
(
changeIndex
,
0
);
});
testWidgets
(
'PageView can restore page'
,
(
WidgetTester
tester
)
async
{
final
PageController
controller
=
new
PageController
();
final
PageStorageBucket
bucket
=
new
PageStorageBucket
();
await
tester
.
pumpWidget
(
new
PageStorage
(
bucket:
bucket
,
child:
new
PageView
(
controller:
controller
,
children:
<
Widget
>[
const
Placeholder
(),
const
Placeholder
(),
const
Placeholder
(),
],
),
),
);
expect
(
controller
.
page
,
0
);
controller
.
jumpToPage
(
2
);
expect
(
await
tester
.
pumpAndSettle
(
const
Duration
(
minutes:
1
)),
1
);
expect
(
controller
.
page
,
2
);
await
tester
.
pumpWidget
(
new
PageStorage
(
bucket:
bucket
,
child:
new
Container
(),
),
);
expect
(()
=>
controller
.
page
,
throwsAssertionError
);
await
tester
.
pumpWidget
(
new
PageStorage
(
bucket:
bucket
,
child:
new
PageView
(
controller:
controller
,
children:
<
Widget
>[
const
Placeholder
(),
const
Placeholder
(),
const
Placeholder
(),
],
),
),
);
expect
(
controller
.
page
,
2
);
await
tester
.
pumpWidget
(
new
PageStorage
(
bucket:
bucket
,
child:
new
PageView
(
key:
const
Key
(
'Check it again against your list and see consistency!'
),
controller:
controller
,
children:
<
Widget
>[
const
Placeholder
(),
const
Placeholder
(),
const
Placeholder
(),
],
),
),
);
expect
(
controller
.
page
,
0
);
});
}
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