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/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/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 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(); +}