-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[go_router] Adds an ability to add a custom codec for serializing/des… #5288
Conversation
@@ -121,6 +122,7 @@ class GoRouter implements RouterConfig<RouteMatchList> { | |||
/// The `routes` must not be null and must contain an [GoRouter] to match `/`. | |||
factory GoRouter({ | |||
required List<RouteBase> routes, | |||
Codec<Object?, Object?>? extraCodec, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been debating what is the best format to provide codec for multiple class type since GoRouter does not limit how many types can be use as extra during its life cycle.
Things I have tried:
- A list
There isn't a way to get what type the codec support, so it is not possible to choose a codec for a given class type - A Map<Type, Codec>
This is fine when encoding the data, but I can't find a good way to get the codec for decoded data.
I end up go with this approach where it would rely on the developer to check the type in their codec and write certain marker in the encoded result to be picked up during decoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if (inputAsList[0] == 'ComplexData2') { | ||
return ComplexData2(inputAsList[1]! as String); | ||
} | ||
throw UnimplementedError(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: most dart SDK decoders seem to throw a FormatException in this case instead, see for example https://master-api.flutter.dev/flutter/dart-convert/Base64Decoder-class.html
case ComplexData2: | ||
return <Object?>['ComplexData2', (input as ComplexData2).data]; | ||
default: | ||
throw UnimplementedError(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same.
@@ -231,6 +233,11 @@ class RouteConfiguration { | |||
/// The global key for top level navigator. | |||
final GlobalKey<NavigatorState> navigatorKey; | |||
|
|||
/// The codec used to encode and decode extra into a serializable format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe link the "extra" to GoRoute.extra or wherever users can learn more about what "extra" is.
// This file deals with json. | ||
// ignore_for_file: avoid_dynamic_calls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am generally not a fan of these blanket ignores and would typecast the json where appropriate to make it clear what types you're expecting to deal with.
Not sure what the policy in this repo is for file-level ignores, though.
@@ -420,13 +452,16 @@ class _RouteMatchListDecoder | |||
RouteMatchList convert(Map<Object?, Object?> input) { | |||
final String rootLocation = | |||
input[RouteMatchListCodec._locationKey]! as String; | |||
final String? encodedExtra = | |||
input[RouteMatchListCodec._extraKey] as String?; | |||
final dynamic encodedExtra = input[RouteMatchListCodec._extraKey]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of dynamic: Seems like you should know the type here (something like Map<String, Object?>
or potentially Map<String, Object?>
, maybe?). If it isn't that, line 458 would just crash.
Co-authored-by: Michael Goderbauer <goderbauer@google.com>
2ede2cc
to
e0f0eae
Compare
flutter/packages@cccf5d2...49eac1f 2023-11-03 katelovett@google.com [two_dimensional_scrollables] Add borderRadius support to TableSpanDecoration (flutter/packages#5184) 2023-11-03 47866232+chunhtai@users.noreply.github.com [go_router] Adds an ability to add a custom codec for serializing/des� (flutter/packages#5288) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
* main: (59 commits) [pointer_interceptor] Move pointer_interceptor to sub folder (flutter#5291) [webview_flutter] Update iOS to Pigeon 13 (flutter#5271) [repo] Adjust error message layout for repo checks (flutter#5241) [in_app_pur]: Bump org.json:json from 20230618 to 20231013 in /packages/in_app_purchase/in_app_purchase/example/android/app (flutter#5153) Roll Flutter from f5a9835 to 5a6a322 (15 revisions) (flutter#5345) [google_sign_in_ios] Upgrade GoogleSignIn iOS SDK to 7.0 (flutter#5240) Roll Flutter from 29b2516 to f5a9835 (101 revisions) (flutter#5341) [pigeon]: Bump org.jetbrains.kotlin:kotlin-gradle-plugin from 1.9.10 to 1.9.20 in /packages/pigeon/platform_tests/test_plugin/android (flutter#5334) [flutter_markdown] Strip leading whitespace from list items (flutter#5294) [two_dimensional_scrollables] Add borderRadius support to TableSpanDecoration (flutter#5184) [go_router] Adds an ability to add a custom codec for serializing/des… (flutter#5288) [go_router] Fixes crashes when dynamically updates routing tables wit… (flutter#5242) [camerax] Fix `_getResolutionSelectorFromPreset` NPE (flutter#5287) [go_router]Fixes the problem what pathParameters is null in redirect when the Router is recreated. (flutter#5258) [google_sign_in] Fix Obj-C formatting bug (flutter#5310) Fix mounted checks (flutter#5305) [flutter_image] [flutter_markdown] Do not use dynamic in an == operator override (flutter#5298) [google_sign_in] Enable FedCM for web. Use token expiration. (flutter#5225) [video_player_web] Listen to loadedmetadata event from video element. (flutter#5289) [local_auth] Update iOS to Pigeon 13 (flutter#5269) ... # Conflicts: # packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m
flutter#5288) �erializing extra fixes flutter/flutter#99099 fixes flutter/flutter#137248
…erializing extra
fixes flutter/flutter#99099
fixes flutter/flutter#137248
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.