File tree Expand file tree Collapse file tree 5 files changed +67
-2
lines changed Expand file tree Collapse file tree 5 files changed +67
-2
lines changed Original file line number Diff line number Diff line change 1+ ## 16.1.0
2+ - Adds annotation for go_router_builder that enable custom string encoder/decoder [ #110781 ] ( https://github.com/flutter/flutter/issues/110781 ) . ** Requires go_router_builder >= 3.1.0** .
3+
14## 16.0.0
25
36- ** BREAKING CHANGE**
3538## 14.8.1
3639
3740- Secured canPop method for the lack of matches in routerDelegate's configuration.
38-
41+
3942## 14.8.0
4043
4144- Adds ` preload ` parameter to ` StatefulShellBranchData.$branch ` .
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ export 'src/configuration.dart';
1111export 'src/delegate.dart' ;
1212export 'src/information_provider.dart' ;
1313export 'src/match.dart' hide RouteMatchListCodec;
14+ export 'src/misc/custom_parameter.dart' ;
1415export 'src/misc/errors.dart' ;
1516export 'src/misc/extensions.dart' ;
1617export 'src/misc/inherited_router.dart' ;
Original file line number Diff line number Diff line change 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:meta/meta_meta.dart' show Target, TargetKind;
6+
7+ /// annotation to define a custom parameter decoder/encoder
8+ /// this is useful when the is encoded/decoded in a non-standard way like base64Url
9+ /// this must be used as an annotation on a field
10+ /// ```dart
11+ /// String fromBase64(String value) {
12+ /// return const Utf8Decoder()
13+ /// .convert(base64Url.decode(base64Url.normalize(value)));
14+ /// }
15+ /// String toBase64(String value) {
16+ /// return base64Url.encode(const Utf8Encoder().convert(value));
17+ /// }
18+ /// @TypedGoRoute<JsonRoute>(path: 'json')
19+ /// class JsonRoute extends GoRouteData with _$EncodedRoute {
20+ /// @CustomParameterCodec(
21+ /// encode: toBase64,
22+ /// decode: fromBase64,
23+ /// )
24+ /// final String data;
25+ /// JsonRoute(this.data);
26+ /// }
27+ /// ```
28+ @Target (< TargetKind > {TargetKind .field})
29+ final class CustomParameterCodec {
30+ /// create a custom parameter codec
31+ ///
32+ const CustomParameterCodec ({
33+ required this .encode,
34+ required this .decode,
35+ });
36+
37+ /// custom function to encode the field
38+ final String Function (String field) encode;
39+
40+ /// custom function to decode the field
41+ final String Function (String field) decode;
42+ }
Original file line number Diff line number Diff line change 11name : go_router
22description : A declarative router for Flutter based on Navigation 2 supporting
33 deep linking, data-driven routes and more
4- version : 16.0 .0
4+ version : 16.1 .0
55repository : https://github.com/flutter/packages/tree/main/packages/go_router
66issue_tracker : https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77
Original file line number Diff line number Diff line change 33// found in the LICENSE file.
44
55import 'dart:async' ;
6+ import 'dart:convert' ;
67
78import 'package:flutter/material.dart' ;
89import 'package:flutter_test/flutter_test.dart' ;
@@ -226,6 +227,14 @@ final List<GoRoute> _routes = <GoRoute>[
226227 _goRouteDataRedirect,
227228];
228229
230+ String fromBase64 (String value) {
231+ return const Utf8Decoder ().convert (base64.decode (value));
232+ }
233+
234+ String toBase64 (String value) {
235+ return base64.encode (const Utf8Encoder ().convert (value));
236+ }
237+
229238void main () {
230239 group ('GoRouteData' , () {
231240 testWidgets (
@@ -633,4 +642,14 @@ void main() {
633642 ),
634643 );
635644 });
645+
646+ test ('CustomParameterCodec with required parameters' , () {
647+ const CustomParameterCodec customParameterCodec = CustomParameterCodec (
648+ encode: toBase64,
649+ decode: fromBase64,
650+ );
651+
652+ expect (customParameterCodec.encode, toBase64);
653+ expect (customParameterCodec.decode, fromBase64);
654+ });
636655}
You can’t perform that action at this time.
0 commit comments