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
e7d63488
Unverified
Commit
e7d63488
authored
Jan 30, 2019
by
Michael Goderbauer
Committed by
GitHub
Jan 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add arguments for pushing named routes (#27058)
parent
f365217e
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
306 additions
and
45 deletions
+306
-45
main.dart
examples/stocks/lib/main.dart
+2
-16
stock_home.dart
examples/stocks/lib/stock_home.dart
+1
-1
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+139
-28
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+146
-0
routes_test.dart
packages/flutter/test/widgets/routes_test.dart
+18
-0
No files found.
examples/stocks/lib/main.dart
View file @
e7d63488
...
...
@@ -84,22 +84,8 @@ class StocksAppState extends State<StocksApp> {
}
Route
<
dynamic
>
_getRoute
(
RouteSettings
settings
)
{
// Routes, by convention, are split on slashes, like filesystem paths.
final
List
<
String
>
path
=
settings
.
name
.
split
(
'/'
);
// We only support paths that start with a slash, so bail if
// the first component is not empty:
if
(
path
[
0
]
!=
''
)
return
null
;
// If the path is "/stock:..." then show a stock page for the
// specified stock symbol.
if
(
path
[
1
].
startsWith
(
'stock:'
))
{
// We don't yet support subpages of a stock, so bail if there's
// any more path components.
if
(
path
.
length
!=
2
)
return
null
;
// Extract the symbol part of "stock:..." and return a route
// for that symbol.
final
String
symbol
=
path
[
1
].
substring
(
6
);
if
(
settings
.
name
==
'/stocks'
)
{
final
String
symbol
=
settings
.
arguments
;
return
MaterialPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
=>
StockSymbolPage
(
symbol:
symbol
,
stocks:
stocks
),
...
...
examples/stocks/lib/stock_home.dart
View file @
e7d63488
...
...
@@ -262,7 +262,7 @@ class StockHomeState extends State<StockHome> {
stocks:
stocks
.
toList
(),
onAction:
_buyStock
,
onOpen:
(
Stock
stock
)
{
Navigator
.
pushNamed
(
context
,
'/stock
:
${stock.symbol}
'
);
Navigator
.
pushNamed
(
context
,
'/stock
'
,
arguments:
stock
.
symbol
);
},
onShow:
(
Stock
stock
)
{
_scaffoldKey
.
currentState
.
showBottomSheet
<
void
>((
BuildContext
context
)
=>
StockSymbolBottomSheet
(
stock:
stock
));
...
...
packages/flutter/lib/src/widgets/navigator.dart
View file @
e7d63488
This diff is collapsed.
Click to expand it.
packages/flutter/test/widgets/navigator_test.dart
View file @
e7d63488
...
...
@@ -4,6 +4,7 @@
import
'dart:ui'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/material.dart'
;
...
...
@@ -870,4 +871,149 @@ void main() {
semantics
.
dispose
();
});
testWidgets
(
'arguments for named routes on Navigator'
,
(
WidgetTester
tester
)
async
{
GlobalKey
currentRouteKey
;
final
List
<
Object
>
arguments
=
<
Object
>[];
await
tester
.
pumpWidget
(
MaterialApp
(
onGenerateRoute:
(
RouteSettings
settings
)
{
arguments
.
add
(
settings
.
arguments
);
return
MaterialPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
=>
Center
(
key:
currentRouteKey
=
GlobalKey
(),
child:
Text
(
settings
.
name
)),
);
},
));
expect
(
find
.
text
(
'/'
),
findsOneWidget
);
expect
(
arguments
.
single
,
isNull
);
arguments
.
clear
();
Navigator
.
pushNamed
(
currentRouteKey
.
currentContext
,
'/A'
,
arguments:
'pushNamed'
,
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/A'
),
findsOneWidget
);
expect
(
arguments
.
single
,
'pushNamed'
);
arguments
.
clear
();
Navigator
.
popAndPushNamed
(
currentRouteKey
.
currentContext
,
'/B'
,
arguments:
'popAndPushNamed'
,
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/A'
),
findsNothing
);
expect
(
find
.
text
(
'/B'
),
findsOneWidget
);
expect
(
arguments
.
single
,
'popAndPushNamed'
);
arguments
.
clear
();
Navigator
.
pushNamedAndRemoveUntil
(
currentRouteKey
.
currentContext
,
'/C'
,
(
Route
<
dynamic
>
route
)
=>
route
.
isFirst
,
arguments:
'pushNamedAndRemoveUntil'
,
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/A'
),
findsNothing
);
expect
(
find
.
text
(
'/B'
),
findsNothing
);
expect
(
find
.
text
(
'/C'
),
findsOneWidget
);
expect
(
arguments
.
single
,
'pushNamedAndRemoveUntil'
);
arguments
.
clear
();
Navigator
.
pushReplacementNamed
(
currentRouteKey
.
currentContext
,
'/D'
,
arguments:
'pushReplacementNamed'
,
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/A'
),
findsNothing
);
expect
(
find
.
text
(
'/B'
),
findsNothing
);
expect
(
find
.
text
(
'/C'
),
findsNothing
);
expect
(
find
.
text
(
'/D'
),
findsOneWidget
);
expect
(
arguments
.
single
,
'pushReplacementNamed'
);
arguments
.
clear
();
});
testWidgets
(
'arguments for named routes on NavigatorState'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NavigatorState
>
navigatorKey
=
GlobalKey
<
NavigatorState
>();
final
List
<
Object
>
arguments
=
<
Object
>[];
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
navigatorKey
,
onGenerateRoute:
(
RouteSettings
settings
)
{
arguments
.
add
(
settings
.
arguments
);
return
MaterialPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
=>
Center
(
child:
Text
(
settings
.
name
)),
);
},
));
expect
(
find
.
text
(
'/'
),
findsOneWidget
);
expect
(
arguments
.
single
,
isNull
);
arguments
.
clear
();
navigatorKey
.
currentState
.
pushNamed
(
'/A'
,
arguments:
'pushNamed'
,
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/A'
),
findsOneWidget
);
expect
(
arguments
.
single
,
'pushNamed'
);
arguments
.
clear
();
navigatorKey
.
currentState
.
popAndPushNamed
(
'/B'
,
arguments:
'popAndPushNamed'
,
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/A'
),
findsNothing
);
expect
(
find
.
text
(
'/B'
),
findsOneWidget
);
expect
(
arguments
.
single
,
'popAndPushNamed'
);
arguments
.
clear
();
navigatorKey
.
currentState
.
pushNamedAndRemoveUntil
(
'/C'
,
(
Route
<
dynamic
>
route
)
=>
route
.
isFirst
,
arguments:
'pushNamedAndRemoveUntil'
,
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/A'
),
findsNothing
);
expect
(
find
.
text
(
'/B'
),
findsNothing
);
expect
(
find
.
text
(
'/C'
),
findsOneWidget
);
expect
(
arguments
.
single
,
'pushNamedAndRemoveUntil'
);
arguments
.
clear
();
navigatorKey
.
currentState
.
pushReplacementNamed
(
'/D'
,
arguments:
'pushReplacementNamed'
,
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'/A'
),
findsNothing
);
expect
(
find
.
text
(
'/B'
),
findsNothing
);
expect
(
find
.
text
(
'/C'
),
findsNothing
);
expect
(
find
.
text
(
'/D'
),
findsOneWidget
);
expect
(
arguments
.
single
,
'pushReplacementNamed'
);
arguments
.
clear
();
});
}
packages/flutter/test/widgets/routes_test.dart
View file @
e7d63488
...
...
@@ -4,6 +4,7 @@
import
'dart:collection'
;
import
'package:flutter/foundation.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -114,6 +115,23 @@ void main() {
expect
(
settings3
.
isInitialRoute
,
true
);
});
testWidgets
(
'Route settings arguments'
,
(
WidgetTester
tester
)
async
{
const
RouteSettings
settings
=
RouteSettings
(
name:
'A'
);
expect
(
settings
.
arguments
,
isNull
);
final
Object
arguments
=
Object
();
final
RouteSettings
settings2
=
RouteSettings
(
name:
'A'
,
arguments:
arguments
);
expect
(
settings2
.
arguments
,
same
(
arguments
));
final
RouteSettings
settings3
=
settings2
.
copyWith
();
expect
(
settings3
.
arguments
,
equals
(
arguments
));
final
Object
arguments2
=
Object
();
final
RouteSettings
settings4
=
settings2
.
copyWith
(
arguments:
arguments2
);
expect
(
settings4
.
arguments
,
same
(
arguments2
));
expect
(
settings4
.
arguments
,
isNot
(
same
(
arguments
)));
});
testWidgets
(
'Route management - push, replace, pop'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NavigatorState
>
navigatorKey
=
GlobalKey
<
NavigatorState
>();
await
tester
.
pumpWidget
(
...
...
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