Skip to content

Commit 040f805

Browse files
authored
update the const in StatefulShellRouteData generation (#8502)
fixes:flutter/flutter#161305 also fix some typos: statefull* -> stateful*
1 parent 2165b5c commit 040f805

9 files changed

+58
-2
lines changed

packages/go_router_builder/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.7.4
2+
3+
- Fixes an issue by removing unnecessary `const` in StatefulShellRouteData generation.
14

25
## 2.7.3
36

packages/go_router_builder/lib/src/route_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class StatefulShellRouteConfig extends RouteBaseConfig {
118118
Iterable<String> classDeclarations() => <String>[
119119
'''
120120
extension $_extensionName on $_className {
121-
static $_className _fromState(GoRouterState state) => const $_className();
121+
static $_className _fromState(GoRouterState state) =>${routeDataClass.unnamedConstructor!.isConst ? ' const' : ''} $_className();
122122
}
123123
'''
124124
];

packages/go_router_builder/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: go_router_builder
22
description: >-
33
A builder that supports generated strongly-typed route helpers for
44
package:go_router
5-
version: 2.7.3
5+
version: 2.7.4
66
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
77
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22
88

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:go_router/go_router.dart';
6+
7+
@TypedStatefulShellRoute<StatefulShellRouteNoConstConstructor>(
8+
branches: <TypedStatefulShellBranch<StatefulShellBranchData>>[
9+
TypedStatefulShellBranch<BranchAData>(),
10+
],
11+
)
12+
class StatefulShellRouteNoConstConstructor extends StatefulShellRouteData {}
13+
14+
@TypedStatefulShellRoute<StatefulShellRouteWithConstConstructor>(
15+
branches: <TypedStatefulShellBranch<StatefulShellBranchData>>[
16+
TypedStatefulShellBranch<BranchAData>(),
17+
],
18+
)
19+
class StatefulShellRouteWithConstConstructor extends StatefulShellRouteData {
20+
const StatefulShellRouteWithConstConstructor();
21+
}
22+
23+
class BranchAData extends StatefulShellBranchData {
24+
const BranchAData();
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
RouteBase get $statefulShellRouteNoConstConstructor =>
2+
StatefulShellRouteData.$route(
3+
factory: $StatefulShellRouteNoConstConstructorExtension._fromState,
4+
branches: [
5+
StatefulShellBranchData.$branch(),
6+
],
7+
);
8+
9+
extension $StatefulShellRouteNoConstConstructorExtension
10+
on StatefulShellRouteNoConstConstructor {
11+
static StatefulShellRouteNoConstConstructor _fromState(GoRouterState state) =>
12+
StatefulShellRouteNoConstConstructor();
13+
}
14+
15+
RouteBase get $statefulShellRouteWithConstConstructor =>
16+
StatefulShellRouteData.$route(
17+
factory: $StatefulShellRouteWithConstConstructorExtension._fromState,
18+
branches: [
19+
StatefulShellBranchData.$branch(),
20+
],
21+
);
22+
23+
extension $StatefulShellRouteWithConstConstructorExtension
24+
on StatefulShellRouteWithConstConstructor {
25+
static StatefulShellRouteWithConstConstructor _fromState(
26+
GoRouterState state) =>
27+
const StatefulShellRouteWithConstConstructor();
28+
}

0 commit comments

Comments
 (0)