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
6f4d84cf
Unverified
Commit
6f4d84cf
authored
Dec 24, 2020
by
chunhtai
Committed by
GitHub
Dec 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve error message when herocontroller is shared by multiple navig… (#72904)
parent
86769843
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
2 deletions
+78
-2
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+22
-2
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+56
-0
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
6f4d84cf
...
...
@@ -3425,8 +3425,28 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
ServicesBinding
.
instance
!.
addPostFrameCallback
((
Duration
timestamp
)
{
// We only check if this navigator still owns the hero controller.
if
(
_heroControllerFromScope
==
newHeroController
)
{
assert
(
_heroControllerFromScope
!.
_navigator
==
this
);
assert
(
previousOwner
.
_heroControllerFromScope
!=
newHeroController
);
final
bool
hasHeroControllerOwnerShip
=
_heroControllerFromScope
!.
_navigator
==
this
;
if
(!
hasHeroControllerOwnerShip
||
previousOwner
.
_heroControllerFromScope
==
newHeroController
)
{
final
NavigatorState
otherOwner
=
hasHeroControllerOwnerShip
?
previousOwner
:
_heroControllerFromScope
!.
_navigator
!;
FlutterError
.
reportError
(
FlutterErrorDetails
(
exception:
FlutterError
(
'A HeroController can not be shared by multiple Navigators. '
'The Navigators that share the same HeroController are:
\n
'
'-
$this
\n
'
'-
$otherOwner
\n
'
'Please create a HeroControllerScope for each Navigator or '
'use a HeroControllerScope.none to prevent subtree from '
'receiving a HeroController.'
),
library
:
'widget library'
,
stack:
StackTrace
.
current
,
),
);
}
}
});
}
...
...
packages/flutter/test/widgets/navigator_test.dart
View file @
6f4d84cf
...
...
@@ -2489,6 +2489,62 @@ void main() {
expect
(
tester
.
takeException
(),
isAssertionError
);
});
testWidgets
(
'hero controller throws has correct error message'
,
(
WidgetTester
tester
)
async
{
final
HeroControllerSpy
spy
=
HeroControllerSpy
();
await
tester
.
pumpWidget
(
HeroControllerScope
(
controller:
spy
,
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Stack
(
children:
<
Widget
>[
Navigator
(
initialRoute:
'navigator1'
,
onGenerateRoute:
(
RouteSettings
s
)
{
return
MaterialPageRoute
<
void
>(
builder:
(
BuildContext
c
)
{
return
const
Placeholder
();
},
settings:
s
,
);
},
),
Navigator
(
initialRoute:
'navigator2'
,
onGenerateRoute:
(
RouteSettings
s
)
{
return
MaterialPageRoute
<
void
>(
builder:
(
BuildContext
c
)
{
return
const
Placeholder
();
},
settings:
s
,
);
},
),
],
),
),
),
);
final
dynamic
exception
=
tester
.
takeException
();
expect
(
exception
,
isFlutterError
);
final
FlutterError
error
=
exception
as
FlutterError
;
expect
(
error
.
toStringDeep
(),
equalsIgnoringHashCodes
(
'FlutterError
\n
'
' A HeroController can not be shared by multiple Navigators. The
\n
'
' Navigators that share the same HeroController are:
\n
'
' - NavigatorState#00000(tickers: tracking 1 ticker)
\n
'
' - NavigatorState#00000(tickers: tracking 1 ticker)
\n
'
' Please create a HeroControllerScope for each Navigator or use a
\n
'
' HeroControllerScope.none to prevent subtree from receiving a
\n
'
' HeroController.
\n
'
''
),
);
});
group
(
'Page api'
,
(){
Widget
buildNavigator
({
required
List
<
Page
<
dynamic
>>
pages
,
...
...
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