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
333eb9d7
Unverified
Commit
333eb9d7
authored
Jun 08, 2020
by
chunhtai
Committed by
GitHub
Jun 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable Navigator.of to accept a navigator element and return its stat… (#58259)
parent
023532d9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
3 deletions
+86
-3
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+11
-3
dialog_test.dart
packages/flutter/test/material/dialog_test.dart
+40
-0
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+35
-0
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
333eb9d7
...
...
@@ -2132,9 +2132,17 @@ class Navigator extends StatefulWidget {
bool
rootNavigator
=
false
,
bool
nullOk
=
false
,
})
{
final
NavigatorState
navigator
=
rootNavigator
?
context
.
findRootAncestorStateOfType
<
NavigatorState
>()
:
context
.
findAncestorStateOfType
<
NavigatorState
>();
// Handles the case where the input context is a navigator element.
NavigatorState
navigator
;
if
(
context
is
StatefulElement
&&
context
.
state
is
NavigatorState
)
{
navigator
=
context
.
state
as
NavigatorState
;
}
if
(
rootNavigator
)
{
navigator
=
context
.
findRootAncestorStateOfType
<
NavigatorState
>()
??
navigator
;
}
else
{
navigator
=
navigator
??
context
.
findAncestorStateOfType
<
NavigatorState
>();
}
assert
(()
{
if
(
navigator
==
null
&&
!
nullOk
)
{
throw
FlutterError
(
...
...
packages/flutter/test/material/dialog_test.dart
View file @
333eb9d7
...
...
@@ -257,6 +257,46 @@ void main() {
expect
(
await
result
,
equals
(
42
));
});
testWidgets
(
'Can show dialog using navigator global key'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NavigatorState
>
navigator
=
GlobalKey
<
NavigatorState
>();
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
navigator
,
home:
const
Material
(
child:
Center
(
child:
Text
(
'Go'
),
),
),
),
);
final
Future
<
int
>
result
=
showDialog
<
int
>(
context:
navigator
.
currentContext
,
builder:
(
BuildContext
context
)
{
return
SimpleDialog
(
title:
const
Text
(
'Title'
),
children:
<
Widget
>[
SimpleDialogOption
(
onPressed:
()
{
Navigator
.
pop
(
context
,
42
);
},
child:
const
Text
(
'First option'
),
),
const
SimpleDialogOption
(
child:
Text
(
'Second option'
),
),
],
);
},
);
await
tester
.
pumpAndSettle
(
const
Duration
(
seconds:
1
));
expect
(
find
.
text
(
'Title'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
text
(
'First option'
));
expect
(
await
result
,
equals
(
42
));
});
testWidgets
(
'Custom padding on SimpleDialogOption'
,
(
WidgetTester
tester
)
async
{
const
EdgeInsets
customPadding
=
EdgeInsets
.
fromLTRB
(
4
,
10
,
8
,
6
);
final
SimpleDialog
dialog
=
SimpleDialog
(
...
...
packages/flutter/test/widgets/navigator_test.dart
View file @
333eb9d7
...
...
@@ -1753,6 +1753,41 @@ void main() {
expect
(
find
.
text
(
'World'
),
findsNothing
);
});
testWidgets
(
'Navigator.of able to handle input context is a navigator context'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NavigatorState
>
g
=
GlobalKey
<
NavigatorState
>();
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
g
,
home:
const
Text
(
'home'
),
)
);
final
NavigatorState
state
=
Navigator
.
of
(
g
.
currentContext
);
expect
(
state
,
g
.
currentState
);
});
testWidgets
(
'Navigator.of able to handle input context is a navigator context - root navigator'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NavigatorState
>
root
=
GlobalKey
<
NavigatorState
>();
final
GlobalKey
<
NavigatorState
>
sub
=
GlobalKey
<
NavigatorState
>();
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
root
,
home:
Navigator
(
key:
sub
,
onGenerateRoute:
(
RouteSettings
settings
)
{
return
MaterialPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
=>
const
Text
(
'dummy'
),
);
},
),
)
);
final
NavigatorState
state
=
Navigator
.
of
(
sub
.
currentContext
,
rootNavigator:
true
);
expect
(
state
,
root
.
currentState
);
});
testWidgets
(
'pushAndRemove until animates the push'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/25080.
...
...
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