Skip to content

[go_router_builder] Update to go_router 6 #2977

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

Merged
merged 3 commits into from
Jan 4, 2023
Merged
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
5 changes: 5 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.16

* Update the documentation to go_router v6.0.0.
* Bumps go_router version in example folder to v6.0.0.

## 1.0.15

* Avoids using deprecated DartType.element2.
Expand Down
24 changes: 12 additions & 12 deletions packages/go_router_builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class HomeRoute extends GoRouteData {
const HomeRoute();

@override
Widget build(BuildContext context) => const HomeScreen();
Widget build(BuildContext context, GoRouterState state) => const HomeScreen();
}
```

Expand All @@ -109,7 +109,7 @@ class HomeRoute extends GoRouteData {
const HomeRoute();

@override
Widget build(BuildContext context) => HomeScreen(families: familyData);
Widget build(BuildContext context, GoRouterState state) => HomeScreen(families: familyData);
}

@TypedGoRoute<LoginRoute>(path: '/login')
Expand All @@ -135,7 +135,7 @@ class ErrorRoute extends GoRouteData {
final Exception error;

@override
Widget build(BuildContext context) => ErrorScreen(error: error);
Widget build(BuildContext context, GoRouterState state) => ErrorScreen(error: error);
}
```

Expand Down Expand Up @@ -175,7 +175,7 @@ class LoginRoute extends GoRouteData {
final String? from;

@override
Widget build(BuildContext context) => LoginScreen(from: from);
Widget build(BuildContext context, GoRouterState state) => LoginScreen(from: from);
}
```

Expand All @@ -190,7 +190,7 @@ class PersonRouteWithExtra extends GoRouteData {
final int? $extra;

@override
Widget build(BuildContext context) => PersonScreen(personId: $extra);
Widget build(BuildContext context, GoRouterState state) => PersonScreen(personId: $extra);
}
```

Expand All @@ -216,7 +216,7 @@ class HotdogRouteWithEverything extends GoRouteData {
final Sauce $extra; // special $extra parameter

@override
Widget build(BuildContext context) => HotdogScreen(ketchup, mustard, $extra);
Widget build(BuildContext context, GoRouterState state) => HotdogScreen(ketchup, mustard, $extra);
}
```

Expand Down Expand Up @@ -245,7 +245,7 @@ Handle route-level redirects by implementing the `redirect` method on the route:
class HomeRoute extends GoRouteData {
// no need to implement [build] when this [redirect] is unconditional
@override
String? redirect() => BooksRoute().location;
String? redirect(BuildContext context, GoRouterState state) => BooksRoute().location;
}
```

Expand All @@ -262,7 +262,7 @@ class BooksRoute extends GoRouteData {
final BookKind kind;

@override
Widget build(BuildContext context) => BooksScreen(kind: kind);
Widget build(BuildContext context, GoRouterState state) => BooksScreen(kind: kind);
}
```

Expand All @@ -279,14 +279,14 @@ of the page and the `restorationId` of the page.

If you'd like to change how the page is created, e.g. to use a different page
type, pass non-default parameters when creating the page (like a custom key) or
access the `GoRouteState` object, you can override the `buildPageWithState`
access the `GoRouteState` object, you can override the `buildPage`
method of the base class instead of the `build` method:

```dart
class MyMaterialRouteWithKey extends GoRouteData {
static final _key = LocalKey('my-route-with-key');
@override
MaterialPage<void> buildPageWithState(BuildContext context, GoRouterState state) =>
MaterialPage<void> buildPage(BuildContext context, GoRouterState state) =>
MaterialPage<void>(
key: _key,
child: MyPage(),
Expand All @@ -296,12 +296,12 @@ class MyMaterialRouteWithKey extends GoRouteData {

### Custom transitions

Overriding the `buildPageWithState` method is also useful for custom transitions:
Overriding the `buildPage` method is also useful for custom transitions:

```dart
class FancyRoute extends GoRouteData {
@override
MaterialPage<void> buildPageWithState(BuildContext context, GoRouterState state) =>
MaterialPage<void> buildPage(BuildContext context, GoRouterState state) =>
CustomTransitionPage<void>(
key: state.pageKey,
child: FancyPage(),
Expand Down
25 changes: 14 additions & 11 deletions packages/go_router_builder/example/lib/all_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class AllTypesBaseRoute extends GoRouteData {
const AllTypesBaseRoute();

@override
Widget build(BuildContext context) => const BasePage<void>(
Widget build(BuildContext context, GoRouterState state) =>
const BasePage<void>(
dataTitle: 'Root',
param: null,
);
Expand All @@ -46,7 +47,7 @@ class BigIntRoute extends GoRouteData {
final BigInt? bigIntField;

@override
Widget build(BuildContext context) => BasePage<BigInt>(
Widget build(BuildContext context, GoRouterState state) => BasePage<BigInt>(
dataTitle: 'BigIntRoute',
param: requiredBigIntField,
queryParam: bigIntField,
Expand All @@ -69,7 +70,7 @@ class BoolRoute extends GoRouteData {
final bool? boolField;

@override
Widget build(BuildContext context) => BasePage<bool>(
Widget build(BuildContext context, GoRouterState state) => BasePage<bool>(
dataTitle: 'BoolRoute',
param: requiredBoolField,
queryParam: boolField,
Expand All @@ -92,7 +93,7 @@ class DateTimeRoute extends GoRouteData {
final DateTime? dateTimeField;

@override
Widget build(BuildContext context) => BasePage<DateTime>(
Widget build(BuildContext context, GoRouterState state) => BasePage<DateTime>(
dataTitle: 'DateTimeRoute',
param: requiredDateTimeField,
queryParam: dateTimeField,
Expand All @@ -115,7 +116,7 @@ class DoubleRoute extends GoRouteData {
final double? doubleField;

@override
Widget build(BuildContext context) => BasePage<double>(
Widget build(BuildContext context, GoRouterState state) => BasePage<double>(
dataTitle: 'DoubleRoute',
param: requiredDoubleField,
queryParam: doubleField,
Expand All @@ -138,7 +139,7 @@ class IntRoute extends GoRouteData {
final int? intField;

@override
Widget build(BuildContext context) => BasePage<int>(
Widget build(BuildContext context, GoRouterState state) => BasePage<int>(
dataTitle: 'IntRoute',
param: requiredIntField,
queryParam: intField,
Expand All @@ -161,7 +162,7 @@ class NumRoute extends GoRouteData {
final num? numField;

@override
Widget build(BuildContext context) => BasePage<num>(
Widget build(BuildContext context, GoRouterState state) => BasePage<num>(
dataTitle: 'NumRoute',
param: requiredNumField,
queryParam: numField,
Expand All @@ -184,7 +185,8 @@ class EnumRoute extends GoRouteData {
final PersonDetails? enumField;

@override
Widget build(BuildContext context) => BasePage<PersonDetails>(
Widget build(BuildContext context, GoRouterState state) =>
BasePage<PersonDetails>(
dataTitle: 'EnumRoute',
param: requiredEnumField,
queryParam: enumField,
Expand All @@ -207,7 +209,8 @@ class EnhancedEnumRoute extends GoRouteData {
final SportDetails? enumField;

@override
Widget build(BuildContext context) => BasePage<SportDetails>(
Widget build(BuildContext context, GoRouterState state) =>
BasePage<SportDetails>(
dataTitle: 'EnhancedEnumRoute',
param: requiredEnumField,
queryParam: enumField,
Expand All @@ -230,7 +233,7 @@ class StringRoute extends GoRouteData {
final String? stringField;

@override
Widget build(BuildContext context) => BasePage<String>(
Widget build(BuildContext context, GoRouterState state) => BasePage<String>(
dataTitle: 'StringRoute',
param: requiredStringField,
queryParam: stringField,
Expand All @@ -253,7 +256,7 @@ class UriRoute extends GoRouteData {
final Uri? uriField;

@override
Widget build(BuildContext context) => BasePage<Uri>(
Widget build(BuildContext context, GoRouterState state) => BasePage<Uri>(
dataTitle: 'UriRoute',
param: requiredUriField,
queryParam: uriField,
Expand Down
12 changes: 7 additions & 5 deletions packages/go_router_builder/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class HomeRoute extends GoRouteData {
const HomeRoute();

@override
Widget build(BuildContext context) => const HomeScreen();
Widget build(BuildContext context, GoRouterState state) => const HomeScreen();
}

@TypedGoRoute<LoginRoute>(
Expand All @@ -95,7 +95,8 @@ class LoginRoute extends GoRouteData {
final String? fromPage;

@override
Widget build(BuildContext context) => LoginScreen(from: fromPage);
Widget build(BuildContext context, GoRouterState state) =>
LoginScreen(from: fromPage);
}

class FamilyRoute extends GoRouteData {
Expand All @@ -104,7 +105,8 @@ class FamilyRoute extends GoRouteData {
final String fid;

@override
Widget build(BuildContext context) => FamilyScreen(family: familyById(fid));
Widget build(BuildContext context, GoRouterState state) =>
FamilyScreen(family: familyById(fid));
}

class PersonRoute extends GoRouteData {
Expand All @@ -114,7 +116,7 @@ class PersonRoute extends GoRouteData {
final int pid;

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, GoRouterState state) {
final Family family = familyById(fid);
final Person person = family.person(pid);
return PersonScreen(family: family, person: person);
Expand All @@ -130,7 +132,7 @@ class PersonDetailsRoute extends GoRouteData {
final int? $extra;

@override
Page<void> buildPageWithState(BuildContext context, GoRouterState state) {
Page<void> buildPage(BuildContext context, GoRouterState state) {
final Family family = familyById(fid);
final Person person = family.person(pid);

Expand Down
4 changes: 2 additions & 2 deletions packages/go_router_builder/example/lib/simple_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HomeRoute extends GoRouteData {
const HomeRoute();

@override
Widget build(BuildContext context) => const HomeScreen();
Widget build(BuildContext context, GoRouterState state) => const HomeScreen();
}

class FamilyRoute extends GoRouteData {
Expand All @@ -45,7 +45,7 @@ class FamilyRoute extends GoRouteData {
final String familyId;

@override
Widget build(BuildContext context) =>
Widget build(BuildContext context, GoRouterState state) =>
FamilyScreen(family: familyById(familyId));
}

Expand Down
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 @@ -8,7 +8,7 @@ environment:
dependencies:
flutter:
sdk: flutter
go_router: ^5.0.0
go_router: ^6.0.0
provider: ^6.0.0

dev_dependencies:
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: 1.0.15
version: 1.0.16
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