Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
54e1576
Add ShellRoute support to go_router_builder
johnpryan Feb 22, 2023
a52bad2
Fix analysis issues
johnpryan Feb 23, 2023
9797546
Fix go_router_builder test
johnpryan Feb 23, 2023
dadb98f
format
johnpryan Feb 23, 2023
2df6775
Increment minor version
johnpryan Feb 23, 2023
b7441ed
ignore deprected member use so downgraded_analyze step passes
johnpryan Feb 23, 2023
5633d15
Revert old TODO
johnpryan Feb 23, 2023
be0a39f
Skip extensions for ShellRoute
johnpryan Feb 23, 2023
6ed5535
Add GoRouterShellGenerator
GP4cK Mar 10, 2023
ce95e76
Add example
GP4cK Mar 10, 2023
bfa3c2f
Merge branch 'main' into feature/shell-route-go-router-builder
GP4cK Mar 10, 2023
1e2606f
Lint shell example
GP4cK Mar 10, 2023
632bf68
Merge branch 'main' into feature/shell-route-go-router-builder
GP4cK Mar 11, 2023
548882a
Revert changes on example/main.dart
GP4cK Mar 11, 2023
7b1305b
Re-run build_runner after merge
GP4cK Mar 11, 2023
75bff09
Fix go_router_builder test
GP4cK Mar 11, 2023
76b9b81
Combine generators
GP4cK Mar 11, 2023
7694e5a
Merge branch 'main' into feature/shell-route-go-router-builder
GP4cK Mar 11, 2023
4600f37
Use element instead of element2
GP4cK Mar 14, 2023
3efeecd
Removed commented import
GP4cK Mar 14, 2023
fb449ff
Add test on shell_route_example
GP4cK Mar 14, 2023
f0924ed
Remove useless comment
GP4cK Mar 14, 2023
6eab717
Fix navigatorKey vs parentNavigatorKey
GP4cK Mar 14, 2023
9f8b067
Ignore deprecation warning
GP4cK Mar 15, 2023
7f4c6e0
Combine GoRouteGenerator to generate a single $appRoutes
GP4cK Mar 16, 2023
0e48f2a
Merge branch 'main' into feature/shell-route-go-router-builder
GP4cK Mar 17, 2023
b08bc6d
Fix builder test after merge
GP4cK Mar 17, 2023
4c08623
Merge branch 'flutter:main' into feature/shell-route-go-router-builder
GP4cK Apr 1, 2023
61c3d9d
Use $navigatorKey / $parentNavigatorKey
GP4cK Apr 4, 2023
3013a05
Add example of navigation with keys
GP4cK Apr 4, 2023
3376c73
Add section about navigator keys in README
GP4cK Apr 4, 2023
219f261
Merge branch 'main' into feature/shell-route-go-router-builder
GP4cK Apr 4, 2023
1832753
Fix linter errors
GP4cK Apr 4, 2023
d7752fd
Add link to example
GP4cK Apr 5, 2023
28e593f
Test shell_route_with_keys_example
GP4cK Apr 5, 2023
6b4ccf1
Merge branch 'main' into feature/shell-route-go-router-builder
GP4cK Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,11 @@ RouteBase get $_routeGetterName => ${_routeDefinition()};
: '''
routes: [${_children.map((RouteConfig e) => '${e._routeDefinition()},').join()}],
''';
final String navigatorKey =
_key == null || _key!.isEmpty ? '' : 'navigatorKey: $_key,';
final String navigatorKeyParameterName =
_isShellRoute ? 'navigatorKey' : 'parentNavigatorKey';
final String navigatorKey = _key == null || _key!.isEmpty
? ''
: '$navigatorKeyParameterName: $_key,';
Comment on lines +337 to +341
Copy link
Contributor Author

@GP4cK GP4cK Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to test this, I was thinking to do the same as in packages/go_router_builder/test/builder_test.dart and use @ShouldGenerate to make sure we use the correct param name like so:

go_router_builder/test/test_inputs/_shell_test_input.dart
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/navigator.dart';
import 'package:go_router/go_router.dart';
import 'package:source_gen_test/source_gen_test.dart';

@ShouldGenerate(r'''
RouteBase get $shellRouteWithKey => ShellRouteData.$route(
      factory: $ShellRouteWithKeyExtension._fromState,
      navigatorKey: ShellRouteWithKey.$navigatorKey, // <- this is what matters
      routes: [
        GoRouteData.$route(
          path: '/foo',
          factory: $GoRouteWithKeyExtension._fromState,
          parentNavigatorKey: GoRouteWithKey.$navigatorKey, // <- this is what matters
        ),
      ],
    );

extension $ShellRouteWithKeyExtension on ShellRouteWithKey {
  static ShellRouteWithKey _fromState(GoRouterState state) =>
      const ShellRouteWithKey();
}

extension $GoRouteWithKeyExtension on GoRouteWithKey {
  static GoRouteWithKey _fromState(GoRouterState state) =>
      const GoRouteWithKey();

  String get location => GoRouteData.$location(
        '/foo',
      );

  void go(BuildContext context) => context.go(location);

  void push(BuildContext context) => context.push(location);

  void pushReplacement(BuildContext context) =>
      context.pushReplacement(location);
}
''')
@TypedShellRoute<ShellRouteWithKey>(
  routes: <TypedRoute<RouteData>>[
    TypedGoRoute<GoRouteWithKey>(path: '/foo'),
  ],
)
class ShellRouteWithKey extends ShellRouteData {
  const ShellRouteWithKey();

  static final GlobalKey<NavigatorState> $navigatorKey =
      GlobalKey<NavigatorState>();
}

class GoRouteWithKey extends GoRouteData {
  const GoRouteWithKey();

  static GlobalKey<NavigatorState> get $navigatorKey => GlobalKey();
}

However, if I do this, I have a warning on the first 2 imports that flutter is not a dependency.
What do you prefer?

  1. Ignore the warning
  2. I add flutter to devDependencies
  3. Other?

That code will never be executed. It's only here to be parsed by the builder as a test so I think 1 is ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add an example in the example folder, and add a test for that example to make sure everything works correctly. We also have a test to ensure the .g.dart is always the latest code. So if someone breaks the route_config.dart either the example test will fail or the .g.dart test will fail.

if (_isShellRoute) {
return '''
ShellRouteData.\$route(
Expand Down