-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[go_router] fix PopScope.onPopInvokedWithResult getting called twice when popping a route if GoRouteData.onExit is not null #8896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
techouse
wants to merge
38
commits into
flutter:main
from
techouse:fix/double-call-onPopInvokedWithResult
Closed
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
3f48e22
fix: call route.didPop(result) when onExit returns true
techouse f8d2118
test: add tests for PopScope onPopInvokedWithResult behavior
techouse e001872
chore: bump version to 14.8.2-dev in pubspec.yaml
techouse d3dfd24
chore: update CHANGELOG for version 14.8.2-dec with PopScope fix
techouse 88d9739
chore: fix typo in changelog
techouse d5cb229
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse fcd8dfc
chore: fix version number
techouse 9ecd5eb
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse ea27f87
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 46b9738
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse ec5184f
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 8a137b9
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 7f4defc
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse d273d97
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 9e23a5c
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse ec6137e
fix: update onExit callback to handle null values and improve type sa…
techouse 6df5625
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 469c8cf
:recycle: convert SubRoute.onExit to a getter
techouse b3f27f8
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 5a8a741
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 6205101
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 57989d4
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse edc3b7c
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 564dd10
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 3a856a1
Merge remote-tracking branch 'origin/main' into fix/double-call-onPop…
techouse 573eefe
Merge remote-tracking branch 'refs/remotes/origin/main' into fix/doub…
techouse a55947f
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse a0c1ae1
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 4a83178
fix: ensure non-null onExit callback usage to prevent potential null …
techouse 6b6d08d
Merge remote-tracking branch 'origin/fix/double-call-onPopInvokedWith…
techouse 15c58a9
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse 9accb64
fix: update onExit to return a FutureOr<bool> and ensure proper callb…
techouse c3e6ace
chore: revert change
techouse 0b3119f
chore: add copyright notice to on_exit_on_pop_invoked_with_result_tes…
techouse c4f47b7
fix: bump version to 15.1.2
techouse 2dff8e8
test: move onPopInvokedWithResult tests to on_exit_test.dart
techouse bd46023
Merge branch 'main' into fix/double-call-onPopInvokedWithResult
techouse a1228df
test: simplify parameters in onPopInvokedWithResult and buildPage met…
techouse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
packages/go_router/test/on_exit_on_pop_invoked_with_result_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
void main() { | ||
testWidgets( | ||
'PopScope onPopInvokedWithResult should be called only once', | ||
(WidgetTester tester) async { | ||
int counter = 0; | ||
|
||
final GoRouter goRouter = GoRouter( | ||
initialLocation: '/', | ||
routes: <GoRoute>[ | ||
GoRoute(path: '/', builder: (_, __) => const DummyStatefulWidget()), | ||
GoRoute( | ||
path: '/page-1', | ||
builder: (_, __) => PopScope( | ||
onPopInvokedWithResult: (bool didPop, __) { | ||
if (didPop) { | ||
counter++; | ||
return; | ||
} | ||
}, | ||
child: const Text('Page 1'), | ||
), | ||
), | ||
], | ||
); | ||
|
||
addTearDown(goRouter.dispose); | ||
|
||
await tester.pumpWidget(MaterialApp.router( | ||
routeInformationProvider: goRouter.routeInformationProvider, | ||
routeInformationParser: goRouter.routeInformationParser, | ||
routerDelegate: goRouter.routerDelegate, | ||
)); | ||
|
||
goRouter.push('/page-1'); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Page 1'), findsOneWidget); | ||
expect( | ||
goRouter.routerDelegate.currentConfiguration.matches.length, | ||
equals(2), | ||
); | ||
expect(goRouter.routerDelegate.canPop(), true); | ||
|
||
goRouter.routerDelegate.pop(); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
expect(counter, equals(1)); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
r'PopScope onPopInvokedWithResult should be called only once with GoRouteData.$route', | ||
(WidgetTester tester) async { | ||
int counter = 0; | ||
|
||
final GoRouter goRouter = GoRouter( | ||
initialLocation: '/', | ||
routes: <GoRoute>[ | ||
GoRoute(path: '/', builder: (_, __) => const DummyStatefulWidget()), | ||
GoRouteData.$route( | ||
path: '/page-1', | ||
factory: (GoRouterState state) => _Page1( | ||
onPop: () { | ||
counter++; | ||
}, | ||
), | ||
), | ||
], | ||
); | ||
|
||
addTearDown(goRouter.dispose); | ||
|
||
await tester.pumpWidget(MaterialApp.router( | ||
routeInformationProvider: goRouter.routeInformationProvider, | ||
routeInformationParser: goRouter.routeInformationParser, | ||
routerDelegate: goRouter.routerDelegate, | ||
)); | ||
|
||
goRouter.push('/page-1'); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Page 1'), findsOneWidget); | ||
expect( | ||
goRouter.routerDelegate.currentConfiguration.matches.length, | ||
equals(2), | ||
); | ||
expect(goRouter.routerDelegate.canPop(), true); | ||
|
||
goRouter.routerDelegate.pop(); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
expect(counter, equals(1)); | ||
}, | ||
); | ||
} | ||
|
||
class _Page1 extends GoRouteData { | ||
const _Page1({ | ||
required this.onPop, | ||
}); | ||
|
||
final VoidCallback onPop; | ||
|
||
@override | ||
Page<void> buildPage(BuildContext context, GoRouterState state) => | ||
MaterialPage<void>( | ||
child: PopScope( | ||
onPopInvokedWithResult: (bool didPop, __) { | ||
if (didPop) { | ||
onPop(); | ||
return; | ||
} | ||
}, | ||
child: const Text('Page 1'), | ||
), | ||
); | ||
} | ||
|
||
class DummyStatefulWidget extends StatefulWidget { | ||
const DummyStatefulWidget({super.key}); | ||
|
||
@override | ||
State<DummyStatefulWidget> createState() => _DummyStatefulWidgetState(); | ||
} | ||
|
||
class _DummyStatefulWidgetState extends State<DummyStatefulWidget> { | ||
@override | ||
Widget build(BuildContext context) => Container(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.