From 864b59b9a116fb91f79c679ea042b9ba95dddf66 Mon Sep 17 00:00:00 2001 From: hangyu Date: Fri, 24 Jan 2025 16:53:55 -0800 Subject: [PATCH 1/2] update const and fix typos --- .../lib/src/route_config.dart | 2 +- ...a.dart => stateful_shell_branch_data.dart} | 0 ...=> stateful_shell_branch_data.dart.expect} | 0 ...ful_shell_branch_with_observers_data.dart} | 0 ...ll_branch_with_observers_data.dart.expect} | 0 .../stateful_shell_route_data.dart | 25 +++++++++++++++++ .../stateful_shell_route_data.dart.expect | 28 +++++++++++++++++++ 7 files changed, 54 insertions(+), 1 deletion(-) rename packages/go_router_builder/test_inputs/{statefull_shell_branch_data.dart => stateful_shell_branch_data.dart} (100%) rename packages/go_router_builder/test_inputs/{statefull_shell_branch_data.dart.expect => stateful_shell_branch_data.dart.expect} (100%) rename packages/go_router_builder/test_inputs/{statefull_shell_branch_with_observers_data.dart => stateful_shell_branch_with_observers_data.dart} (100%) rename packages/go_router_builder/test_inputs/{statefull_shell_branch_with_observers_data.dart.expect => stateful_shell_branch_with_observers_data.dart.expect} (100%) create mode 100644 packages/go_router_builder/test_inputs/stateful_shell_route_data.dart create mode 100644 packages/go_router_builder/test_inputs/stateful_shell_route_data.dart.expect diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index 0cfa7a3928c..b773c533ac1 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -118,7 +118,7 @@ class StatefulShellRouteConfig extends RouteBaseConfig { Iterable classDeclarations() => [ ''' extension $_extensionName on $_className { - static $_className _fromState(GoRouterState state) => const $_className(); + static $_className _fromState(GoRouterState state) =>${routeDataClass.unnamedConstructor!.isConst ? ' const' : ''} $_className(); } ''' ]; diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart b/packages/go_router_builder/test_inputs/stateful_shell_branch_data.dart similarity index 100% rename from packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart rename to packages/go_router_builder/test_inputs/stateful_shell_branch_data.dart diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect b/packages/go_router_builder/test_inputs/stateful_shell_branch_data.dart.expect similarity index 100% rename from packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect rename to packages/go_router_builder/test_inputs/stateful_shell_branch_data.dart.expect diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart b/packages/go_router_builder/test_inputs/stateful_shell_branch_with_observers_data.dart similarity index 100% rename from packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart rename to packages/go_router_builder/test_inputs/stateful_shell_branch_with_observers_data.dart diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart.expect b/packages/go_router_builder/test_inputs/stateful_shell_branch_with_observers_data.dart.expect similarity index 100% rename from packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart.expect rename to packages/go_router_builder/test_inputs/stateful_shell_branch_with_observers_data.dart.expect diff --git a/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart b/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart new file mode 100644 index 00000000000..3d5b4771e99 --- /dev/null +++ b/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart @@ -0,0 +1,25 @@ +// 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:go_router/go_router.dart'; + +@TypedStatefulShellRoute( + branches: >[ + TypedStatefulShellBranch(), + ], +) +class StatefulShellRouteNoConstConstructor extends StatefulShellRouteData {} + +@TypedStatefulShellRoute( + branches: >[ + TypedStatefulShellBranch(), + ], +) +class StatefulShellRouteWithConstConstructor extends StatefulShellRouteData { + const StatefulShellRouteWithConstConstructor(); +} + +class BranchAData extends StatefulShellBranchData { + const BranchAData(); +} diff --git a/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart.expect b/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart.expect new file mode 100644 index 00000000000..df121eb6f0f --- /dev/null +++ b/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart.expect @@ -0,0 +1,28 @@ +RouteBase get $statefulShellRouteNoConstConstructor => + StatefulShellRouteData.$route( + factory: $StatefulShellRouteNoConstConstructorExtension._fromState, + branches: [ + StatefulShellBranchData.$branch(), + ], + ); + +extension $StatefulShellRouteNoConstConstructorExtension + on StatefulShellRouteNoConstConstructor { + static StatefulShellRouteNoConstConstructor _fromState(GoRouterState state) => + StatefulShellRouteNoConstConstructor(); +} + +RouteBase get $statefulShellRouteWithConstConstructor => + StatefulShellRouteData.$route( + factory: $StatefulShellRouteWithConstConstructorExtension._fromState, + branches: [ + StatefulShellBranchData.$branch(), + ], + ); + +extension $StatefulShellRouteWithConstConstructorExtension + on StatefulShellRouteWithConstConstructor { + static StatefulShellRouteWithConstConstructor _fromState( + GoRouterState state) => + const StatefulShellRouteWithConstConstructor(); +} From d93424ffcd8e0b9234ad3078db57609e8f5b39da Mon Sep 17 00:00:00 2001 From: hangyu Date: Fri, 24 Jan 2025 17:20:24 -0800 Subject: [PATCH 2/2] bump version --- packages/go_router_builder/CHANGELOG.md | 3 +++ packages/go_router_builder/pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 687d9210f05..7dfd69d4499 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.7.4 + +- Fixes an issue by removing unnecessary `const` in StatefulShellRouteData generation. ## 2.7.3 diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 692b81f0796..1f4e9da1504 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -2,7 +2,7 @@ name: go_router_builder description: >- A builder that supports generated strongly-typed route helpers for package:go_router -version: 2.7.3 +version: 2.7.4 repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22