Skip to content

[go_router_builder] Change mixin name #9626

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 3.1.0

- Restricts `build` to versions less than 2.5.0.
- Make the mixin public if the route class is not in the same file.

## 3.0.1

Expand Down
35 changes: 35 additions & 0 deletions packages/go_router_builder/example/lib/separate_file_route.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.

// ignore_for_file: public_member_api_docs, unreachable_from_main

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import 'stateful_shell_route_initial_location_example.dart';

class OrdersRouteData extends GoRouteData with $OrdersRouteData {
const OrdersRouteData();

@override
Widget build(BuildContext context, GoRouterState state) {
return const OrdersPageView(label: 'Orders page');
}
}

class OrdersPageView extends StatelessWidget {
const OrdersPageView({
required this.label,
super.key,
});

final String label;

@override
Widget build(BuildContext context) {
return Center(
child: Text(label),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import 'separate_file_route.dart';

part 'stateful_shell_route_initial_location_example.g.dart';

void main() => runApp(App());
Expand Down Expand Up @@ -118,15 +120,6 @@ class NotificationsRouteData extends GoRouteData with _$NotificationsRouteData {
}
}

class OrdersRouteData extends GoRouteData with _$OrdersRouteData {
const OrdersRouteData();

@override
Widget build(BuildContext context, GoRouterState state) {
return const OrdersPageView(label: 'Orders page');
}
}

class MainPageView extends StatelessWidget {
const MainPageView({
required this.navigationShell,
Expand Down Expand Up @@ -258,19 +251,3 @@ class NotificationsSubPageView extends StatelessWidget {
);
}
}

class OrdersPageView extends StatelessWidget {
const OrdersPageView({
required this.label,
super.key,
});

final String label;

@override
Widget build(BuildContext context) {
return Center(
child: Text(label),
);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ShellRouteConfig extends RouteBaseConfig {
required this.navigatorKey,
required this.parentNavigatorKey,
required super.routeDataClass,
required super.targetUri,
required this.observers,
required super.parent,
required this.restorationScopeId,
Expand Down Expand Up @@ -101,6 +102,7 @@ class StatefulShellRouteConfig extends RouteBaseConfig {
StatefulShellRouteConfig._({
required this.parentNavigatorKey,
required super.routeDataClass,
required super.targetUri,
required super.parent,
required this.navigatorContainerBuilder,
required this.restorationScopeId,
Expand Down Expand Up @@ -146,6 +148,7 @@ class StatefulShellBranchConfig extends RouteBaseConfig {
StatefulShellBranchConfig._({
required this.navigatorKey,
required super.routeDataClass,
required super.targetUri,
required super.parent,
required this.observers,
this.restorationScopeId,
Expand Down Expand Up @@ -197,6 +200,7 @@ class GoRouteConfig extends RouteBaseConfig {
required this.caseSensitive,
required this.parentNavigatorKey,
required super.routeDataClass,
required super.targetUri,
required super.parent,
}) : super._();

Expand Down Expand Up @@ -483,6 +487,7 @@ mixin $_mixinName on GoRouteData {
abstract class RouteBaseConfig {
RouteBaseConfig._({
required this.routeDataClass,
required this.targetUri,
required this.parent,
});

Expand Down Expand Up @@ -525,11 +530,14 @@ abstract class RouteBaseConfig {
// TODO(kevmoo): validate that this MUST be a subtype of `GoRouteData`
final InterfaceElement classElement = typeParamType.element;

final Uri targetUri = element.source.uri;

final RouteBaseConfig value;
switch (typeName) {
case 'TypedShellRoute':
value = ShellRouteConfig._(
routeDataClass: classElement,
targetUri: targetUri,
parent: parent,
navigatorKey: _generateParameterGetterCode(
classElement,
Expand All @@ -551,6 +559,7 @@ abstract class RouteBaseConfig {
case 'TypedStatefulShellRoute':
value = StatefulShellRouteConfig._(
routeDataClass: classElement,
targetUri: targetUri,
parent: parent,
parentNavigatorKey: _generateParameterGetterCode(
classElement,
Expand All @@ -568,6 +577,7 @@ abstract class RouteBaseConfig {
case 'TypedStatefulShellBranch':
value = StatefulShellBranchConfig._(
routeDataClass: classElement,
targetUri: targetUri,
parent: parent,
navigatorKey: _generateParameterGetterCode(
classElement,
Expand Down Expand Up @@ -605,6 +615,7 @@ abstract class RouteBaseConfig {
name: nameValue.isNull ? null : nameValue.stringValue,
caseSensitive: caseSensitiveValue.boolValue,
routeDataClass: classElement,
targetUri: targetUri,
parent: parent,
parentNavigatorKey: _generateParameterGetterCode(
classElement,
Expand All @@ -629,6 +640,9 @@ abstract class RouteBaseConfig {
/// The `RouteData` class this class represents.
final InterfaceElement routeDataClass;

/// The URI of the file where the code will be generated.
final Uri targetUri;

/// The parent of this route config.
final RouteBaseConfig? parent;

Expand Down Expand Up @@ -729,7 +743,11 @@ RouteBase get $_routeGetterName => ${_invokesRouteConstructor()};

String get _className => routeDataClass.name;

String get _mixinName => '_\$$_className';
String get _mixinName {
// If the routeDataClass is in a different file, we need to make the mixin public
final Uri routeUri = routeDataClass.source.uri;
return routeUri != targetUri ? '\$$_className' : '_\$$_className';
}

String get _extensionName => '\$${_className}Extension';

Expand Down
2 changes: 1 addition & 1 deletion packages/go_router_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: go_router_builder
description: >-
A builder that supports generated strongly-typed route helpers for
package:go_router
version: 3.0.1
version: 3.1.0
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

Expand Down