Skip to content
Closed
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,5 +1,6 @@
## NEXT
## 3.0.2

- Adds support for `TypedRelativeGoRoute`.
- Restricts `build` to versions less than 2.5.0.

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

part 'go_relative.g.dart';

void main() => runApp(const MyApp());

/// The main app.
class MyApp extends StatelessWidget {
/// Constructs a [MyApp]
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _router,
);
}
}

/// The route configuration.
final GoRouter _router = GoRouter(
routes: $appRoutes,
);
const TypedRelativeGoRoute<DetailsRoute> detailRoute =
TypedRelativeGoRoute<DetailsRoute>(
path: 'details/:detailId',
routes: <TypedRoute<RouteData>>[
TypedRelativeGoRoute<SettingsRoute>(path: 'settings/:settingId'),
Copy link

Choose a reason for hiding this comment

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

What will happen if this is another TypedGoRoute? or should we assert or force the type of the routes to TypedRelativeGoRoute or TypedShellRoute?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I added a build-time check in RouteBaseConfig._fromAnnotation. Do you agree with that approach?
Do you think it's necessary to add an assert in TypedRelativeGoRoute as well?

],
);

@TypedGoRoute<HomeRoute>(
path: '/',
routes: <TypedRoute<RouteData>>[
TypedGoRoute<DashboardRoute>(
path: '/dashboard',
routes: <TypedRoute<RouteData>>[detailRoute],
),
detailRoute,
],
)
class HomeRoute extends GoRouteData with _$HomeRoute {
@override
Widget build(BuildContext context, GoRouterState state) {
return const HomeScreen();
}
}

class DashboardRoute extends GoRouteData with _$DashboardRoute {
@override
Widget build(BuildContext context, GoRouterState state) {
return const DashboardScreen();
}
}

class DetailsRoute extends RelativeGoRouteData with _$DetailsRoute {
const DetailsRoute({required this.detailId});
final String detailId;

@override
Widget build(BuildContext context, GoRouterState state) {
return DetailsScreen(id: detailId);
}
}

class SettingsRoute extends RelativeGoRouteData with _$SettingsRoute {
const SettingsRoute({
required this.settingId,
});
final String settingId;

@override
Widget build(BuildContext context, GoRouterState state) {
return SettingsScreen(id: settingId);
}
}

/// The home screen
class HomeScreen extends StatelessWidget {
/// Constructs a [HomeScreen]
const HomeScreen({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Home Screen')),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () {
const DetailsRoute(detailId: 'DetailsId').goRelative(context);
},
child: const Text('Go to the Details screen'),
),
ElevatedButton(
onPressed: () {
DashboardRoute().go(context);
},
child: const Text('Go to the Dashboard screen'),
),
],
),
);
}
}

/// The home screen
class DashboardScreen extends StatelessWidget {
/// Constructs a [DashboardScreen]
const DashboardScreen({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Dashboard Screen')),
body: Column(
children: <Widget>[
ElevatedButton(
onPressed: () {
const DetailsRoute(detailId: 'DetailsId').goRelative(context);
},
child: const Text('Go to the Details screen'),
),
ElevatedButton(
onPressed: () => context.pop(),
child: const Text('Go back'),
),
],
),
);
}
}

/// The details screen
class DetailsScreen extends StatelessWidget {
/// Constructs a [DetailsScreen]
const DetailsScreen({
super.key,
required this.id,
});

final String id;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Details Screen $id')),
body: Center(
child: Column(
children: <Widget>[
ElevatedButton(
onPressed: () => context.pop(),
child: const Text('Go back'),
),
ElevatedButton(
onPressed: () => const SettingsRoute(
settingId: 'SettingsId',
).goRelative(context),
child: const Text('Go to the Settings screen'),
),
],
),
),
);
}
}

/// The details screen
class SettingsScreen extends StatelessWidget {
/// Constructs a [SettingsScreen]
const SettingsScreen({
super.key,
required this.id,
});

final String id;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Settings Screen $id')),
body: Center(
child: TextButton(
onPressed: () => context.pop(),
child: const Text('Go back'),
),
),
);
}
}
152 changes: 152 additions & 0 deletions packages/go_router_builder/example/lib/go_relative.g.dart

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

2 changes: 1 addition & 1 deletion packages/go_router_builder/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
collection: ^1.15.0
flutter:
sdk: flutter
go_router: ^16.0.0
go_router: ^16.1.1
provider: 6.0.5

dev_dependencies:
Expand Down
Loading