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
4877c061
Commit
4877c061
authored
Oct 29, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PageStorage support to Navigator2
parent
e904ab57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
2 deletions
+109
-2
page.dart
packages/flutter/lib/src/widgets/page.dart
+7
-2
page_storage.dart
packages/flutter/lib/src/widgets/page_storage.dart
+102
-0
No files found.
packages/flutter/lib/src/widgets/page.dart
View file @
4877c061
...
...
@@ -8,6 +8,7 @@ import 'basic.dart';
import
'framework.dart'
;
import
'navigator2.dart'
;
import
'overlay.dart'
;
import
'page_storage.dart'
;
import
'transitions.dart'
;
// TODO(abarth): Should we add a type for the result?
...
...
@@ -81,8 +82,9 @@ class _PageState extends State<_Page> {
Widget
build
(
BuildContext
context
)
{
if
(
config
.
route
.
_offstage
)
{
return
new
OffStage
(
child:
new
KeyedSubtre
e
(
child:
new
PageStorag
e
(
key:
_subtreeKey
,
bucket:
config
.
route
.
_storageBucket
,
child:
_invokeBuilder
()
)
);
...
...
@@ -93,8 +95,9 @@ class _PageState extends State<_Page> {
child:
new
FadeTransition
(
performance:
config
.
route
.
performance
,
opacity:
_opacity
,
child:
new
KeyedSubtre
e
(
child:
new
PageStorag
e
(
key:
_subtreeKey
,
bucket:
config
.
route
.
_storageBucket
,
child:
_invokeBuilder
()
)
)
...
...
@@ -132,6 +135,8 @@ class PageRoute extends TransitionRoute {
Duration
get
transitionDuration
=>
const
Duration
(
milliseconds:
150
);
List
<
Widget
>
createWidgets
()
=>
[
new
_Page
(
key:
pageKey
,
route:
this
)
];
final
PageStorageBucket
_storageBucket
=
new
PageStorageBucket
();
bool
get
offstage
=>
_offstage
;
bool
_offstage
=
false
;
void
set
offstage
(
bool
value
)
{
...
...
packages/flutter/lib/src/widgets/page_storage.dart
0 → 100644
View file @
4877c061
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'framework.dart'
;
class
_StorageEntryIdentifier
{
Type
clientType
;
List
<
Key
>
keys
;
void
addKey
(
Key
key
)
{
assert
(
key
!=
null
);
assert
(
key
is
!
GlobalKey
);
keys
??=
<
Key
>[];
keys
.
add
(
key
);
}
GlobalKey
scopeKey
;
bool
operator
==(
dynamic
other
)
{
if
(
other
is
!
_StorageEntryIdentifier
)
return
false
;
final
_StorageEntryIdentifier
typedOther
=
other
;
if
(
clientType
!=
typedOther
.
clientType
||
scopeKey
!=
typedOther
.
scopeKey
||
keys
?.
length
!=
typedOther
.
keys
?.
length
)
return
false
;
if
(
keys
!=
null
)
{
for
(
int
index
=
0
;
index
<
keys
.
length
;
index
+=
1
)
{
if
(
keys
[
index
]
!=
typedOther
.
keys
[
index
])
return
false
;
}
}
return
true
;
}
int
get
hashCode
{
int
value
=
373
;
value
=
37
*
value
+
clientType
.
hashCode
;
value
=
37
*
value
+
scopeKey
.
hashCode
;
if
(
keys
!=
null
)
{
for
(
Key
key
in
keys
)
value
=
37
*
value
+
key
.
hashCode
;
}
return
value
;
}
}
class
PageStorageBucket
{
_StorageEntryIdentifier
_computeStorageIdentifier
(
BuildContext
context
)
{
_StorageEntryIdentifier
result
=
new
_StorageEntryIdentifier
();
result
.
clientType
=
context
.
widget
.
runtimeType
;
Key
lastKey
=
context
.
widget
.
key
;
if
(
lastKey
is
!
GlobalKey
)
{
context
.
visitAncestorElements
((
Element
element
)
{
if
(
element
.
widget
.
key
is
GlobalKey
)
{
lastKey
=
element
.
widget
.
key
;
return
false
;
}
else
if
(
element
.
widget
.
key
!=
null
)
{
result
.
addKey
(
element
.
widget
.
key
);
}
return
true
;
});
return
result
;
}
assert
(
lastKey
is
GlobalKey
);
result
.
scopeKey
=
lastKey
;
return
result
;
}
Map
<
_StorageEntryIdentifier
,
dynamic
>
_storage
;
void
writeState
(
BuildContext
context
,
dynamic
data
)
{
_storage
??=
<
_StorageEntryIdentifier
,
dynamic
>{};
_storage
[
_computeStorageIdentifier
(
context
)]
=
data
;
}
dynamic
readState
(
BuildContext
context
)
{
return
_storage
!=
null
?
_storage
[
_computeStorageIdentifier
(
context
)]
:
null
;
}
}
class
PageStorage
extends
StatelessComponent
{
PageStorage
({
Key
key
,
this
.
child
,
this
.
bucket
})
:
super
(
key:
key
);
final
Widget
child
;
final
PageStorageBucket
bucket
;
/// Might return null if there is no PageStorage in this context.
static
PageStorageBucket
of
(
BuildContext
context
)
{
PageStorageBucket
result
;
context
.
visitAncestorElements
((
Element
element
)
{
Widget
widget
=
element
.
widget
;
if
(
widget
is
PageStorage
)
{
result
=
widget
.
bucket
;
return
false
;
}
return
true
;
});
return
result
;
}
Widget
build
(
BuildContext
context
)
=>
child
;
}
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