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
8f07fcce
Unverified
Commit
8f07fcce
authored
Jan 06, 2021
by
chunhtai
Committed by
GitHub
Jan 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
app bar leading back button should not change if the route is popped (#71944)
parent
161dde55
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
3 deletions
+100
-3
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+8
-2
routes.dart
packages/flutter/lib/src/widgets/routes.dart
+1
-1
app_bar_test.dart
packages/flutter/test/material/app_bar_test.dart
+91
-0
No files found.
packages/flutter/lib/src/material/app_bar.dart
View file @
8f07fcce
...
@@ -709,6 +709,8 @@ class _AppBarState extends State<AppBar> {
...
@@ -709,6 +709,8 @@ class _AppBarState extends State<AppBar> {
Scaffold
.
of
(
context
).
openEndDrawer
();
Scaffold
.
of
(
context
).
openEndDrawer
();
}
}
bool
?
hadBackButtonWhenRouteWasActive
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(!
widget
.
primary
||
debugCheckHasMediaQuery
(
context
));
assert
(!
widget
.
primary
||
debugCheckHasMediaQuery
(
context
));
...
@@ -721,7 +723,11 @@ class _AppBarState extends State<AppBar> {
...
@@ -721,7 +723,11 @@ class _AppBarState extends State<AppBar> {
final
bool
hasDrawer
=
scaffold
?.
hasDrawer
??
false
;
final
bool
hasDrawer
=
scaffold
?.
hasDrawer
??
false
;
final
bool
hasEndDrawer
=
scaffold
?.
hasEndDrawer
??
false
;
final
bool
hasEndDrawer
=
scaffold
?.
hasEndDrawer
??
false
;
final
bool
canPop
=
parentRoute
?.
canPop
??
false
;
hadBackButtonWhenRouteWasActive
??=
false
;
if
(
parentRoute
?.
isActive
==
true
)
{
hadBackButtonWhenRouteWasActive
=
parentRoute
!.
canPop
;
}
assert
(
hadBackButtonWhenRouteWasActive
!=
null
);
final
bool
useCloseButton
=
parentRoute
is
PageRoute
<
dynamic
>
&&
parentRoute
.
fullscreenDialog
;
final
bool
useCloseButton
=
parentRoute
is
PageRoute
<
dynamic
>
&&
parentRoute
.
fullscreenDialog
;
final
double
toolbarHeight
=
widget
.
toolbarHeight
??
kToolbarHeight
;
final
double
toolbarHeight
=
widget
.
toolbarHeight
??
kToolbarHeight
;
...
@@ -790,7 +796,7 @@ class _AppBarState extends State<AppBar> {
...
@@ -790,7 +796,7 @@ class _AppBarState extends State<AppBar> {
tooltip:
MaterialLocalizations
.
of
(
context
).
openAppDrawerTooltip
,
tooltip:
MaterialLocalizations
.
of
(
context
).
openAppDrawerTooltip
,
);
);
}
else
{
}
else
{
if
(!
hasEndDrawer
&&
canPop
)
if
(!
hasEndDrawer
&&
hadBackButtonWhenRouteWasActive
!
)
leading
=
useCloseButton
?
const
CloseButton
()
:
const
BackButton
();
leading
=
useCloseButton
?
const
CloseButton
()
:
const
BackButton
();
}
}
}
}
...
...
packages/flutter/lib/src/widgets/routes.dart
View file @
8f07fcce
...
@@ -1460,7 +1460,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
...
@@ -1460,7 +1460,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
/// When this changes, if the route is visible, the route will
/// When this changes, if the route is visible, the route will
/// rebuild, and any widgets that used [ModalRoute.of] will be
/// rebuild, and any widgets that used [ModalRoute.of] will be
/// notified.
/// notified.
bool
get
canPop
=>
!
isFirst
||
willHandlePopInternally
;
bool
get
canPop
=>
isActive
&&
(!
isFirst
||
willHandlePopInternally
)
;
// Internals
// Internals
...
...
packages/flutter/test/material/app_bar_test.dart
View file @
8f07fcce
...
@@ -1122,6 +1122,97 @@ void main() {
...
@@ -1122,6 +1122,97 @@ void main() {
expect
(
find
.
byIcon
(
Icons
.
menu
),
findsNothing
);
expect
(
find
.
byIcon
(
Icons
.
menu
),
findsNothing
);
});
});
testWidgets
(
'AppBar does not update the leading if a route is popped case 1'
,
(
WidgetTester
tester
)
async
{
final
Page
<
void
>
page1
=
MaterialPage
<
void
>(
key:
const
ValueKey
<
String
>(
'1'
),
child:
Scaffold
(
key:
const
ValueKey
<
String
>(
'1'
),
appBar:
AppBar
(),
)
);
final
Page
<
void
>
page2
=
MaterialPage
<
void
>(
key:
const
ValueKey
<
String
>(
'2'
),
child:
Scaffold
(
key:
const
ValueKey
<
String
>(
'2'
),
appBar:
AppBar
(),
)
);
List
<
Page
<
void
>>
pages
=
<
Page
<
void
>>[
page1
];
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Navigator
(
pages:
pages
,
onPopPage:
(
Route
<
dynamic
>
route
,
dynamic
result
)
=>
false
,
),
),
);
expect
(
find
.
byType
(
BackButton
),
findsNothing
);
// Update pages
pages
=
<
Page
<
void
>>[
page2
];
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Navigator
(
pages:
pages
,
onPopPage:
(
Route
<
dynamic
>
route
,
dynamic
result
)
=>
false
,
),
),
);
expect
(
find
.
byType
(
BackButton
),
findsNothing
);
});
testWidgets
(
'AppBar does not update the leading if a route is popped case 2'
,
(
WidgetTester
tester
)
async
{
final
Page
<
void
>
page1
=
MaterialPage
<
void
>(
key:
const
ValueKey
<
String
>(
'1'
),
child:
Scaffold
(
key:
const
ValueKey
<
String
>(
'1'
),
appBar:
AppBar
(),
)
);
final
Page
<
void
>
page2
=
MaterialPage
<
void
>(
key:
const
ValueKey
<
String
>(
'2'
),
child:
Scaffold
(
key:
const
ValueKey
<
String
>(
'2'
),
appBar:
AppBar
(),
)
);
List
<
Page
<
void
>>
pages
=
<
Page
<
void
>>[
page1
,
page2
];
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Navigator
(
pages:
pages
,
onPopPage:
(
Route
<
dynamic
>
route
,
dynamic
result
)
=>
false
,
),
),
);
// The page2 should have a back button
expect
(
find
.
descendant
(
of:
find
.
byKey
(
const
ValueKey
<
String
>(
'2'
)),
matching:
find
.
byType
(
BackButton
),
),
findsOneWidget
);
// Update pages
pages
=
<
Page
<
void
>>[
page1
];
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Navigator
(
pages:
pages
,
onPopPage:
(
Route
<
dynamic
>
route
,
dynamic
result
)
=>
false
,
),
),
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
// The back button should persist during the pop animation.
expect
(
find
.
descendant
(
of:
find
.
byKey
(
const
ValueKey
<
String
>(
'2'
)),
matching:
find
.
byType
(
BackButton
),
),
findsOneWidget
);
});
testWidgets
(
'AppBar ink splash draw on the correct canvas'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'AppBar ink splash draw on the correct canvas'
,
(
WidgetTester
tester
)
async
{
// This is a regression test for https://github.com/flutter/flutter/issues/58665
// This is a regression test for https://github.com/flutter/flutter/issues/58665
final
Key
key
=
UniqueKey
();
final
Key
key
=
UniqueKey
();
...
...
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