Skip to content

[go_router] add initial json support #110781 #9404

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 15.1.4

- Adds annotation for go_router_builder that enable custom string encoder/decoder [#110781](https://github.com/flutter/flutter/issues/110781)

## 15.1.3

* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
Expand Down
1 change: 1 addition & 0 deletions packages/go_router/lib/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export 'src/configuration.dart';
export 'src/delegate.dart';
export 'src/information_provider.dart';
export 'src/match.dart' hide RouteMatchListCodec;
export 'src/misc/custom_parameter.dart';
export 'src/misc/errors.dart';
export 'src/misc/extensions.dart';
export 'src/misc/inherited_router.dart';
Expand Down
40 changes: 40 additions & 0 deletions packages/go_router/lib/src/misc/custom_parameter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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:meta/meta_meta.dart';

/// annotation to define a custom parameter decoder/encoder
/// this is useful when the is encoded/decoded in a non-standard way like base64
/// this must be used as an annotation on a field
/// ```dart
/// String fromBase64(String value) {
/// return const Utf8Decoder().convert(base64.decode(value));
/// }
/// String toBase64(String value) {
/// return base64.encode(const Utf8Encoder().convert(value));
/// }
/// class MyRoute {
/// @CustomParameterCodec(
/// encode: toBase64,
/// decode: fromBase64,
/// )
/// final String data;
/// MyRoute(this.data);
/// }
/// ```
@Target({TargetKind.field})
class CustomParameterCodec {
/// create a custom parameter codec
///
const CustomParameterCodec({
required this.encode,
required this.decode,
});

/// custom function to encode the field
final String Function(String json) encode;

/// custom function to decode the field
final String Function(String json) decode;
}
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 15.1.3
version: 15.1.4
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down