-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[go_router] Add buildPageWithState
#2444
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
Merged
auto-submit
merged 23 commits into
flutter:main
from
ValentinVignal:go-router/expose-go-router-state-in-page-builder
Sep 6, 2022
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b1ec0ad
:sparkles: Add `buildPageWithState`
ValentinVignal 1a4a22a
:arrow_up: Upgrade version number
ValentinVignal 8d90548
Merge remote-tracking branch 'upstream/main' into go-router/expose-go…
ValentinVignal d61584b
:wastebasket: Deprecate buildPage
ValentinVignal b67e5f8
:recycle: buildPageWithState uses buildPage
ValentinVignal 2b80b52
:white_check_mark: Add tests for build buildPage and buildPageWithState
ValentinVignal b473d7a
:memo: Update the CHANGELOG
ValentinVignal ef2d9fc
:rotating_light: Add licence
ValentinVignal 32b94eb
:rotating_light: Fix linter
ValentinVignal 12bad41
:bulb: Update comments and doc
ValentinVignal f89bb7e
:memo: Update example
ValentinVignal d40e8b9
:arrow_up: Upgrade go_router_builder version
ValentinVignal 0b51946
:rotating_light: Add ignore in go_router_builder example
ValentinVignal d5f9c92
:rewind: Continue to use buildPage in go_router_builder and ignore fu…
ValentinVignal 4d3f7b6
Merge remote-tracking branch 'upstream/main' into go-router/expose-go…
ValentinVignal 03b9e52
Merge remote-tracking branch 'upstream/main' into go-router/expose-go…
ValentinVignal 8a72d8d
🔀 Fix merge conflict
ValentinVignal d782698
Merge remote-tracking branch 'upstream/main' into go-router/expose-go…
ValentinVignal 93c849a
Merge branch 'main' into go-router/expose-go-router-state-in-page-bui…
ValentinVignal 4aa9150
:rewind: revert changes on go_router_builder
ValentinVignal 66b94df
:rewind: revert changes on go_router_builder
ValentinVignal 732927e
Update packages/go_router/CHANGELOG.md
ValentinVignal 3802759
Merge remote-tracking branch 'upstream/main' into go-router/expose-go…
ValentinVignal 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:go_router/go_router.dart'; | ||
|
|
||
| class _GoRouteDataBuild extends GoRouteData { | ||
| const _GoRouteDataBuild(); | ||
| @override | ||
| Widget build(BuildContext context) => const SizedBox(key: Key('build')); | ||
| } | ||
|
|
||
| final GoRoute _goRouteDataBuild = GoRouteData.$route( | ||
| path: '/build', | ||
| factory: (GoRouterState state) => const _GoRouteDataBuild(), | ||
| ); | ||
|
|
||
| class _GoRouteDataBuildPage extends GoRouteData { | ||
| const _GoRouteDataBuildPage(); | ||
| @override | ||
| Page<void> buildPage(BuildContext context) => const MaterialPage<void>( | ||
| child: SizedBox(key: Key('buildPage')), | ||
| ); | ||
| } | ||
|
|
||
| final GoRoute _goRouteDataBuildPage = GoRouteData.$route( | ||
| path: '/build-page', | ||
| factory: (GoRouterState state) => const _GoRouteDataBuildPage(), | ||
| ); | ||
|
|
||
| class _GoRouteDataBuildPageWithState extends GoRouteData { | ||
| const _GoRouteDataBuildPageWithState(); | ||
| @override | ||
| Page<void> buildPageWithState(BuildContext context, GoRouterState state) => | ||
| const MaterialPage<void>( | ||
| child: SizedBox(key: Key('buildPageWithState')), | ||
| ); | ||
| } | ||
|
|
||
| final GoRoute _goRouteDataBuildPageWithState = GoRouteData.$route( | ||
| path: '/build-page-with-state', | ||
| factory: (GoRouterState state) => const _GoRouteDataBuildPageWithState(), | ||
| ); | ||
|
|
||
| final List<GoRoute> _routes = <GoRoute>[ | ||
| _goRouteDataBuild, | ||
| _goRouteDataBuildPage, | ||
| _goRouteDataBuildPageWithState, | ||
| ]; | ||
|
|
||
| void main() { | ||
| testWidgets( | ||
| 'It should build the page from the overridden build method', | ||
| (WidgetTester tester) async { | ||
| final GoRouter goRouter = GoRouter( | ||
| initialLocation: '/build', | ||
| routes: _routes, | ||
| ); | ||
| await tester.pumpWidget(MaterialApp.router( | ||
| routeInformationProvider: goRouter.routeInformationProvider, | ||
| routeInformationParser: goRouter.routeInformationParser, | ||
| routerDelegate: goRouter.routerDelegate, | ||
| )); | ||
| expect(find.byKey(const Key('build')), findsOneWidget); | ||
| expect(find.byKey(const Key('buildPage')), findsNothing); | ||
| expect(find.byKey(const Key('buildPageWithState')), findsNothing); | ||
| }, | ||
| ); | ||
|
|
||
| testWidgets( | ||
| 'It should build the page from the overridden buildPage method', | ||
| (WidgetTester tester) async { | ||
| final GoRouter goRouter = GoRouter( | ||
| initialLocation: '/build-page', | ||
| routes: _routes, | ||
| ); | ||
| await tester.pumpWidget(MaterialApp.router( | ||
| routeInformationProvider: goRouter.routeInformationProvider, | ||
| routeInformationParser: goRouter.routeInformationParser, | ||
| routerDelegate: goRouter.routerDelegate, | ||
| )); | ||
| expect(find.byKey(const Key('build')), findsNothing); | ||
| expect(find.byKey(const Key('buildPage')), findsOneWidget); | ||
| expect(find.byKey(const Key('buildPageWithState')), findsNothing); | ||
| }, | ||
| ); | ||
|
|
||
| testWidgets( | ||
| 'It should build the page from the overridden buildPageWithState method', | ||
| (WidgetTester tester) async { | ||
| final GoRouter goRouter = GoRouter( | ||
| initialLocation: '/build-page-with-state', | ||
| routes: _routes, | ||
| ); | ||
| await tester.pumpWidget(MaterialApp.router( | ||
| routeInformationProvider: goRouter.routeInformationProvider, | ||
| routeInformationParser: goRouter.routeInformationParser, | ||
| routerDelegate: goRouter.routerDelegate, | ||
| )); | ||
| expect(find.byKey(const Key('build')), findsNothing); | ||
| expect(find.byKey(const Key('buildPage')), findsNothing); | ||
| expect(find.byKey(const Key('buildPageWithState')), findsOneWidget); | ||
| }, | ||
| ); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return buildPage by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I did it in b67e5f8