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
+
1
4
## 16.0.0
2
5
3
6
- ** BREAKING CHANGE**
35
38
## 14.8.1
36
39
37
40
- Secured canPop method for the lack of matches in routerDelegate's configuration.
38
-
41
+
39
42
## 14.8.0
40
43
41
44
- Adds ` preload ` parameter to ` StatefulShellBranchData.$branch ` .
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ export 'src/configuration.dart';
11
11
export 'src/delegate.dart' ;
12
12
export 'src/information_provider.dart' ;
13
13
export 'src/match.dart' hide RouteMatchListCodec;
14
+ export 'src/misc/custom_parameter.dart' ;
14
15
export 'src/misc/errors.dart' ;
15
16
export 'src/misc/extensions.dart' ;
16
17
export '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 1
1
name : go_router
2
2
description : A declarative router for Flutter based on Navigation 2 supporting
3
3
deep linking, data-driven routes and more
4
- version : 16.0 .0
4
+ version : 16.1 .0
5
5
repository : https://github.com/flutter/packages/tree/main/packages/go_router
6
6
issue_tracker : https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
7
7
Original file line number Diff line number Diff line change 3
3
// found in the LICENSE file.
4
4
5
5
import 'dart:async' ;
6
+ import 'dart:convert' ;
6
7
7
8
import 'package:flutter/material.dart' ;
8
9
import 'package:flutter_test/flutter_test.dart' ;
@@ -226,6 +227,14 @@ final List<GoRoute> _routes = <GoRoute>[
226
227
_goRouteDataRedirect,
227
228
];
228
229
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
+
229
238
void main () {
230
239
group ('GoRouteData' , () {
231
240
testWidgets (
@@ -633,4 +642,14 @@ void main() {
633
642
),
634
643
);
635
644
});
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
+ });
636
655
}
You can’t perform that action at this time.
0 commit comments