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
0b6af5aa
Unverified
Commit
0b6af5aa
authored
Dec 31, 2020
by
Shi-Hao Hong
Committed by
GitHub
Dec 31, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Navigator assert on non restorable routes returned by onGenerateInitialRoutes (#73082)
parent
efc84ab1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+7
-0
navigator_restoration_test.dart
...ages/flutter/test/widgets/navigator_restoration_test.dart
+38
-0
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
0b6af5aa
...
...
@@ -3388,6 +3388,13 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
}
}
assert
(
_history
.
isNotEmpty
,
'All routes returned by onGenerateInitialRoutes are not restorable. '
'Please make sure that all routes returned by onGenerateInitialRoutes '
'have their RouteSettings defined with names that are defined in the '
'app
\'
s routes table.'
,
);
assert
(!
_debugLocked
);
assert
(()
{
_debugLocked
=
true
;
return
true
;
}());
_flushHistoryUpdates
();
...
...
packages/flutter/test/widgets/navigator_restoration_test.dart
View file @
0b6af5aa
...
...
@@ -981,6 +981,44 @@ void main() {
await
tester
.
pumpAndSettle
();
expect
(
findRoute
(
'p1'
,
count:
0
),
findsOneWidget
);
});
testWidgets
(
'Helpful assert thrown all routes in onGenerateInitialRoutes are not restorable'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
restorationScopeId:
'material_app'
,
initialRoute:
'/'
,
routes:
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
=>
Container
(),
},
onGenerateInitialRoutes:
(
String
initialRoute
)
{
return
<
MaterialPageRoute
<
void
>>[
MaterialPageRoute
<
void
>(
builder:
(
BuildContext
context
)
=>
Container
(),
),
];
},
),
);
await
tester
.
restartAndRestore
();
final
dynamic
exception
=
tester
.
takeException
();
expect
(
exception
,
isAssertionError
);
expect
(
(
exception
as
AssertionError
).
message
,
contains
(
'All routes returned by onGenerateInitialRoutes are not restorable.'
),
);
// The previous assert leaves the widget tree in a broken state, so the
// following code catches any remaining exceptions from attempting to build
// new widget tree.
final
FlutterExceptionHandler
?
oldHandler
=
FlutterError
.
onError
;
dynamic
remainingException
;
FlutterError
.
onError
=
(
FlutterErrorDetails
details
)
{
remainingException
??=
details
.
exception
;
};
await
tester
.
pumpWidget
(
Container
(
key:
UniqueKey
()));
FlutterError
.
onError
=
oldHandler
;
expect
(
remainingException
,
isAssertionError
);
});
}
Route
<
void
>
_routeBuilder
(
BuildContext
context
,
Object
?
arguments
)
{
...
...
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