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
97fd3ce9
Unverified
Commit
97fd3ce9
authored
Apr 15, 2021
by
xubaolin
Committed by
GitHub
Apr 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix a BackButtonListener bug (#80355)
parent
e7b7ebc0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
0 deletions
+59
-0
router.dart
packages/flutter/lib/src/widgets/router.dart
+1
-0
router_test.dart
packages/flutter/test/widgets/router_test.dart
+58
-0
No files found.
packages/flutter/lib/src/widgets/router.dart
View file @
97fd3ce9
...
@@ -1052,6 +1052,7 @@ class _BackButtonListenerState extends State<BackButtonListener> {
...
@@ -1052,6 +1052,7 @@ class _BackButtonListenerState extends State<BackButtonListener> {
if
(
oldWidget
.
onBackButtonPressed
!=
widget
.
onBackButtonPressed
)
{
if
(
oldWidget
.
onBackButtonPressed
!=
widget
.
onBackButtonPressed
)
{
dispatcher
?.
removeCallback
(
oldWidget
.
onBackButtonPressed
);
dispatcher
?.
removeCallback
(
oldWidget
.
onBackButtonPressed
);
dispatcher
?.
addCallback
(
widget
.
onBackButtonPressed
);
dispatcher
?.
addCallback
(
widget
.
onBackButtonPressed
);
dispatcher
?.
takePriority
();
}
}
super
.
didUpdateWidget
(
oldWidget
);
super
.
didUpdateWidget
(
oldWidget
);
}
}
...
...
packages/flutter/test/widgets/router_test.dart
View file @
97fd3ce9
...
@@ -1032,6 +1032,64 @@ testWidgets('ChildBackButtonDispatcher take priority recursively', (WidgetTester
...
@@ -1032,6 +1032,64 @@ testWidgets('ChildBackButtonDispatcher take priority recursively', (WidgetTester
await
tester
.
pump
();
await
tester
.
pump
();
expect
(
find
.
text
(
'popped inner1'
),
findsOneWidget
);
expect
(
find
.
text
(
'popped inner1'
),
findsOneWidget
);
});
});
testWidgets
(
'`didUpdateWidget` test'
,
(
WidgetTester
tester
)
async
{
final
SimpleRouteInformationProvider
provider
=
SimpleRouteInformationProvider
();
provider
.
value
=
const
RouteInformation
(
location:
'initial'
,
);
final
BackButtonDispatcher
outerDispatcher
=
RootBackButtonDispatcher
();
late
StateSetter
setState
;
String
location
=
'first callback'
;
final
SimpleRouterDelegate
routerDelegate
=
SimpleRouterDelegate
()
..
builder
=
(
BuildContext
context
,
RouteInformation
?
information
)
{
// Creates the sub-router.
return
Column
(
children:
<
Widget
>[
Text
(
information
!.
location
!),
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setter
)
{
setState
=
setter
;
return
BackButtonListener
(
child:
Container
(),
onBackButtonPressed:
()
{
provider
.
value
=
RouteInformation
(
location:
location
,
);
return
SynchronousFuture
<
bool
>(
true
);
},
);
},
),
],
);
}
..
onPopRoute
=
()
{
provider
.
value
=
const
RouteInformation
(
location:
'popped outter'
,
);
return
SynchronousFuture
<
bool
>(
true
);
};
await
tester
.
pumpWidget
(
buildBoilerPlate
(
Router
<
RouteInformation
>(
backButtonDispatcher:
outerDispatcher
,
routeInformationProvider:
provider
,
routeInformationParser:
SimpleRouteInformationParser
(),
routerDelegate:
routerDelegate
)
));
// Only update BackButtonListener widget.
setState
((){
location
=
'second callback'
;
});
await
tester
.
pump
();
await
outerDispatcher
.
invokeCallback
(
SynchronousFuture
<
bool
>(
false
));
await
tester
.
pump
();
expect
(
find
.
text
(
'second callback'
),
findsOneWidget
);
});
}
}
Widget
buildBoilerPlate
(
Widget
child
)
{
Widget
buildBoilerPlate
(
Widget
child
)
{
...
...
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