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
b68c69aa
Unverified
Commit
b68c69aa
authored
Oct 13, 2022
by
chunhtai
Committed by
GitHub
Oct 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pushnamed can handle Object as type (#113242)
parent
34995ba9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
36 deletions
+56
-36
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+6
-6
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+50
-30
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
b68c69aa
...
...
@@ -4073,7 +4073,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
return
index
<
_history
.
length
?
_history
[
index
]
:
null
;
}
Route
<
T
>?
_routeNamed
<
T
>(
String
name
,
{
required
Object
?
arguments
,
bool
allowNull
=
false
})
{
Route
<
T
?
>?
_routeNamed
<
T
>(
String
name
,
{
required
Object
?
arguments
,
bool
allowNull
=
false
})
{
assert
(!
_debugLocked
);
assert
(
name
!=
null
);
if
(
allowNull
&&
widget
.
onGenerateRoute
==
null
)
{
...
...
@@ -4096,7 +4096,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
name:
name
,
arguments:
arguments
,
);
Route
<
T
>?
route
=
widget
.
onGenerateRoute
!(
settings
)
as
Route
<
T
>?;
Route
<
T
?>?
route
=
widget
.
onGenerateRoute
!(
settings
)
as
Route
<
T
?
>?;
if
(
route
==
null
&&
!
allowNull
)
{
assert
(()
{
if
(
widget
.
onUnknownRoute
==
null
)
{
...
...
@@ -4111,7 +4111,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
}
return
true
;
}());
route
=
widget
.
onUnknownRoute
!(
settings
)
as
Route
<
T
>?;
route
=
widget
.
onUnknownRoute
!(
settings
)
as
Route
<
T
?
>?;
assert
(()
{
if
(
route
==
null
)
{
throw
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
...
...
@@ -4155,7 +4155,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
String
routeName
,
{
Object
?
arguments
,
})
{
return
push
<
T
>(
_routeNamed
<
T
>(
routeName
,
arguments:
arguments
)!);
return
push
<
T
?
>(
_routeNamed
<
T
>(
routeName
,
arguments:
arguments
)!);
}
/// Push a named route onto the navigator.
...
...
@@ -4225,7 +4225,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
TO
?
result
,
Object
?
arguments
,
})
{
return
pushReplacement
<
T
,
TO
>(
_routeNamed
<
T
>(
routeName
,
arguments:
arguments
)!,
result:
result
);
return
pushReplacement
<
T
?
,
TO
>(
_routeNamed
<
T
>(
routeName
,
arguments:
arguments
)!,
result:
result
);
}
/// Replace the current route of the navigator by pushing the route named
...
...
@@ -4362,7 +4362,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
RoutePredicate
predicate
,
{
Object
?
arguments
,
})
{
return
pushAndRemoveUntil
<
T
>(
_routeNamed
<
T
>(
newRouteName
,
arguments:
arguments
)!,
predicate
);
return
pushAndRemoveUntil
<
T
?
>(
_routeNamed
<
T
>(
newRouteName
,
arguments:
arguments
)!,
predicate
);
}
/// Push the route with the given name onto the navigator, and then remove all
...
...
packages/flutter/test/widgets/navigator_test.dart
View file @
b68c69aa
...
...
@@ -318,36 +318,56 @@ void main() {
expect
(
log
,
equals
(<
String
>[
'left'
]));
});
testWidgets
(
'Pending gestures are rejected'
,
(
WidgetTester
tester
)
async
{
final
List
<
String
>
log
=
<
String
>[];
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
{
return
Row
(
children:
<
Widget
>[
GestureDetector
(
onTap:
()
{
log
.
add
(
'left'
);
Navigator
.
pushNamed
(
context
,
'/second'
);
},
child:
const
Text
(
'left'
),
),
GestureDetector
(
onTap:
()
{
log
.
add
(
'right'
);
},
child:
const
Text
(
'right'
),
),
],
);
},
'/second'
:
(
BuildContext
context
)
=>
Container
(),
};
await
tester
.
pumpWidget
(
MaterialApp
(
routes:
routes
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'right'
)),
pointer:
23
);
expect
(
log
,
isEmpty
);
await
tester
.
tap
(
find
.
text
(
'left'
),
pointer:
1
);
expect
(
log
,
equals
(<
String
>[
'left'
]));
await
gesture
.
up
();
expect
(
log
,
equals
(<
String
>[
'left'
]));
});
testWidgets
(
'pushnamed can handle Object as type'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NavigatorState
>
nav
=
GlobalKey
<
NavigatorState
>();
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
=>
const
Text
(
'/'
),
'/second'
:
(
BuildContext
context
)
=>
const
Text
(
'/second'
),
};
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
nav
,
routes:
routes
));
expect
(
find
.
text
(
'/'
),
findsOneWidget
);
Error
?
error
;
try
{
nav
.
currentState
!.
pushNamed
<
Object
>(
'/second'
);
}
on
Error
catch
(
e
)
{
error
=
e
;
}
expect
(
error
,
isNull
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/second'
),
findsOneWidget
);
});
testWidgets
(
'Pending gestures are rejected'
,
(
WidgetTester
tester
)
async
{
final
List
<
String
>
log
=
<
String
>[];
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
{
return
Row
(
children:
<
Widget
>[
GestureDetector
(
onTap:
()
{
log
.
add
(
'left'
);
Navigator
.
pushNamed
(
context
,
'/second'
);
},
child:
const
Text
(
'left'
),
),
GestureDetector
(
onTap:
()
{
log
.
add
(
'right'
);
},
child:
const
Text
(
'right'
),
),
],
);
},
'/second'
:
(
BuildContext
context
)
=>
Container
(),
};
await
tester
.
pumpWidget
(
MaterialApp
(
routes:
routes
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'right'
)),
pointer:
23
);
expect
(
log
,
isEmpty
);
await
tester
.
tap
(
find
.
text
(
'left'
),
pointer:
1
);
expect
(
log
,
equals
(<
String
>[
'left'
]));
await
gesture
.
up
();
expect
(
log
,
equals
(<
String
>[
'left'
]));
});
testWidgets
(
'popAndPushNamed'
,
(
WidgetTester
tester
)
async
{
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
...
...
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