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
65f232fd
Unverified
Commit
65f232fd
authored
Mar 19, 2021
by
Michael Goderbauer
Committed by
GitHub
Mar 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add restorationId to Material/CupertinoPage (#78450)
parent
fd37a50f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
203 additions
and
2 deletions
+203
-2
route.dart
packages/flutter/lib/src/cupertino/route.dart
+2
-1
page.dart
packages/flutter/lib/src/material/page.dart
+2
-1
page_test.dart
packages/flutter/test/cupertino/page_test.dart
+101
-0
page_test.dart
packages/flutter/test/material/page_test.dart
+98
-0
No files found.
packages/flutter/lib/src/cupertino/route.dart
View file @
65f232fd
...
...
@@ -401,10 +401,11 @@ class CupertinoPage<T> extends Page<T> {
LocalKey
?
key
,
String
?
name
,
Object
?
arguments
,
String
?
restorationId
,
})
:
assert
(
child
!=
null
),
assert
(
maintainState
!=
null
),
assert
(
fullscreenDialog
!=
null
),
super
(
key:
key
,
name:
name
,
arguments:
arguments
);
super
(
key:
key
,
name:
name
,
arguments:
arguments
,
restorationId:
restorationId
);
/// The content to be shown in the [Route] created by this page.
final
Widget
child
;
...
...
packages/flutter/lib/src/material/page.dart
View file @
65f232fd
...
...
@@ -156,10 +156,11 @@ class MaterialPage<T> extends Page<T> {
LocalKey
?
key
,
String
?
name
,
Object
?
arguments
,
String
?
restorationId
,
})
:
assert
(
child
!=
null
),
assert
(
maintainState
!=
null
),
assert
(
fullscreenDialog
!=
null
),
super
(
key:
key
,
name:
name
,
arguments:
arguments
);
super
(
key:
key
,
name:
name
,
arguments:
arguments
,
restorationId:
restorationId
);
/// The content to be shown in the [Route] created by this page.
final
Widget
child
;
...
...
packages/flutter/test/cupertino/page_test.dart
View file @
65f232fd
...
...
@@ -475,6 +475,68 @@ void main() {
expect
(
find
.
text
(
'subpage'
),
findsOneWidget
);
expect
(
find
.
text
(
'home'
),
findsOneWidget
);
});
testWidgets
(
'CupertinoPage restores its state'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
RootRestorationScope
(
restorationId:
'root'
,
child:
MediaQuery
(
data:
const
MediaQueryData
(),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Navigator
(
onPopPage:
(
Route
<
dynamic
>
route
,
dynamic
result
)
{
return
false
;
},
pages:
const
<
Page
<
Object
?>>[
CupertinoPage
<
void
>(
restorationId:
'p1'
,
child:
TestRestorableWidget
(
restorationId:
'p1'
),
),
],
restorationScopeId:
'nav'
,
onGenerateRoute:
(
RouteSettings
settings
)
{
return
CupertinoPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
{
return
TestRestorableWidget
(
restorationId:
settings
.
name
!);
},
);
},
),
),
),
),
);
expect
(
find
.
text
(
'p1'
),
findsOneWidget
);
expect
(
find
.
text
(
'count: 0'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
text
(
'increment'
));
await
tester
.
pump
();
expect
(
find
.
text
(
'count: 1'
),
findsOneWidget
);
tester
.
state
<
NavigatorState
>(
find
.
byType
(
Navigator
)).
restorablePushNamed
(
'p2'
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'p1'
),
findsNothing
);
expect
(
find
.
text
(
'p2'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
text
(
'increment'
));
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'increment'
));
await
tester
.
pump
();
expect
(
find
.
text
(
'count: 2'
),
findsOneWidget
);
await
tester
.
restartAndRestore
();
expect
(
find
.
text
(
'p2'
),
findsOneWidget
);
expect
(
find
.
text
(
'count: 2'
),
findsOneWidget
);
tester
.
state
<
NavigatorState
>(
find
.
byType
(
Navigator
)).
pop
();
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'p1'
),
findsOneWidget
);
expect
(
find
.
text
(
'count: 1'
),
findsOneWidget
);
});
}
class
RtlOverrideWidgetsDelegate
extends
LocalizationsDelegate
<
WidgetsLocalizations
>
{
...
...
@@ -527,3 +589,42 @@ class _KeepsStateTestWidgetState extends State<KeepsStateTestWidget> {
);
}
}
class
TestRestorableWidget
extends
StatefulWidget
{
const
TestRestorableWidget
({
Key
?
key
,
required
this
.
restorationId
})
:
super
(
key:
key
);
final
String
restorationId
;
@override
State
<
StatefulWidget
>
createState
()
=>
_TestRestorableWidgetState
();
}
class
_TestRestorableWidgetState
extends
State
<
TestRestorableWidget
>
with
RestorationMixin
{
@override
String
?
get
restorationId
=>
widget
.
restorationId
;
final
RestorableInt
counter
=
RestorableInt
(
0
);
@override
void
restoreState
(
RestorationBucket
?
oldBucket
,
bool
initialRestore
)
{
registerForRestoration
(
counter
,
'counter'
);
}
@override
Widget
build
(
BuildContext
context
)
{
return
Column
(
children:
<
Widget
>[
Text
(
widget
.
restorationId
),
Text
(
'count:
${counter.value}
'
),
CupertinoButton
(
onPressed:
()
{
setState
(()
{
counter
.
value
++;
});
},
child:
const
Text
(
'increment'
),
),
],
);
}
}
packages/flutter/test/material/page_test.dart
View file @
65f232fd
...
...
@@ -913,6 +913,65 @@ void main() {
expect
(
find
.
text
(
'subpage'
),
findsOneWidget
);
expect
(
find
.
text
(
'home'
),
findsOneWidget
);
});
testWidgets
(
'MaterialPage restores its state'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
RootRestorationScope
(
restorationId:
'root'
,
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Navigator
(
onPopPage:
(
Route
<
dynamic
>
route
,
dynamic
result
)
{
return
false
;
},
pages:
const
<
Page
<
Object
?>>[
MaterialPage
<
void
>(
restorationId:
'p1'
,
child:
TestRestorableWidget
(
restorationId:
'p1'
),
),
],
restorationScopeId:
'nav'
,
onGenerateRoute:
(
RouteSettings
settings
)
{
return
MaterialPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
{
return
TestRestorableWidget
(
restorationId:
settings
.
name
!);
},
);
},
),
),
),
);
expect
(
find
.
text
(
'p1'
),
findsOneWidget
);
expect
(
find
.
text
(
'count: 0'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
text
(
'increment'
));
await
tester
.
pump
();
expect
(
find
.
text
(
'count: 1'
),
findsOneWidget
);
tester
.
state
<
NavigatorState
>(
find
.
byType
(
Navigator
)).
restorablePushNamed
(
'p2'
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'p1'
),
findsNothing
);
expect
(
find
.
text
(
'p2'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
text
(
'increment'
));
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'increment'
));
await
tester
.
pump
();
expect
(
find
.
text
(
'count: 2'
),
findsOneWidget
);
await
tester
.
restartAndRestore
();
expect
(
find
.
text
(
'p2'
),
findsOneWidget
);
expect
(
find
.
text
(
'count: 2'
),
findsOneWidget
);
tester
.
state
<
NavigatorState
>(
find
.
byType
(
Navigator
)).
pop
();
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'p1'
),
findsOneWidget
);
expect
(
find
.
text
(
'count: 1'
),
findsOneWidget
);
});
}
class
TransitionDetector
extends
DefaultTransitionDelegate
<
void
>
{
...
...
@@ -993,3 +1052,42 @@ class _KeepsStateTestWidgetState extends State<KeepsStateTestWidget> {
);
}
}
class
TestRestorableWidget
extends
StatefulWidget
{
const
TestRestorableWidget
({
Key
?
key
,
required
this
.
restorationId
})
:
super
(
key:
key
);
final
String
restorationId
;
@override
State
<
StatefulWidget
>
createState
()
=>
_TestRestorableWidgetState
();
}
class
_TestRestorableWidgetState
extends
State
<
TestRestorableWidget
>
with
RestorationMixin
{
@override
String
?
get
restorationId
=>
widget
.
restorationId
;
final
RestorableInt
counter
=
RestorableInt
(
0
);
@override
void
restoreState
(
RestorationBucket
?
oldBucket
,
bool
initialRestore
)
{
registerForRestoration
(
counter
,
'counter'
);
}
@override
Widget
build
(
BuildContext
context
)
{
return
Column
(
children:
<
Widget
>[
Text
(
widget
.
restorationId
),
Text
(
'count:
${counter.value}
'
),
ElevatedButton
(
onPressed:
()
{
setState
(()
{
counter
.
value
++;
});
},
child:
const
Text
(
'increment'
),
),
],
);
}
}
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