-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router_builder] Add support for Iterable, List and Set to TypedGoRoute #2679
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
auto-submit
merged 12 commits into
flutter:main
from
Skogsfrae:feature/#108437_support-for-iterables
Feb 23, 2023
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b2c18aa
fixes #108437 support for iterable, list and set
Skogsfrae 280c8dd
fixes #108437 url encoding for iterable, list and set
Skogsfrae a083136
fixes #108437 tests
Skogsfrae 32a4f8a
format and analysis fix
Skogsfrae 3dee0f0
fix string encoding
Skogsfrae 94b1497
format
Skogsfrae 48cbcf7
removed unused helper name
Skogsfrae f1d39c6
fix nullability checks for query params encoding
Skogsfrae 5a52fc0
fix all_types.dart for new go router version
Skogsfrae 5f604cd
rebased to upstream
Skogsfrae 1d74193
version
Skogsfrae a6a0e1a
missing file regeneration
Skogsfrae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fixes #108437 support for iterable, list and set
- Loading branch information
commit b2c18aa5e63a9dbb4c2ca01ea839663c8655c4ac
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ const String durationDecoderHelperName = r'_$duractionConverter'; | |
| /// The name of the generated, private helper for converting [String] to [Enum]. | ||
| const String enumExtensionHelperName = r'_$fromName'; | ||
|
|
||
| /// The name of the generated, private helper for converting [String] to [Enum]. | ||
|
||
| const String iterableDecoderHelperName = r'_$iterableConverter'; | ||
|
|
||
| /// The property/parameter name used to represent the `extra` data that may | ||
| /// be passed to a route. | ||
| const String extraFieldName = r'$extra'; | ||
|
|
@@ -38,6 +41,7 @@ const List<_TypeHelper> _helpers = <_TypeHelper>[ | |
| _TypeHelperNum(), | ||
| _TypeHelperString(), | ||
| _TypeHelperUri(), | ||
| _TypeHelperIterable(), | ||
| ]; | ||
|
|
||
| /// Returns the decoded [String] value for [element], if its type is supported. | ||
|
|
@@ -253,6 +257,49 @@ class _TypeHelperUri extends _TypeHelperWithHelper { | |
| const TypeChecker.fromRuntime(Uri).isAssignableFromType(type); | ||
| } | ||
|
|
||
| class _TypeHelperIterable extends _TypeHelper { | ||
| const _TypeHelperIterable(); | ||
|
|
||
| @override | ||
| String _decode(ParameterElement parameterElement) { | ||
| if (parameterElement.type is ParameterizedType) { | ||
| final DartType iterableType = | ||
| (parameterElement.type as ParameterizedType).typeArguments.first; | ||
|
|
||
| String entriesTypeMapper = '(e) => e'; | ||
| for (final _TypeHelper helper in _helpers) { | ||
| if (helper._matchesType(iterableType) && | ||
| helper is _TypeHelperWithHelper) { | ||
| entriesTypeMapper = helper.helperName(iterableType); | ||
| } | ||
| } | ||
|
|
||
| String iterableCaster = ''; | ||
| if (const TypeChecker.fromRuntime(List) | ||
| .isAssignableFromType(parameterElement.type)) { | ||
| iterableCaster = '.toList()'; | ||
| } else if (const TypeChecker.fromRuntime(Set) | ||
| .isAssignableFromType(parameterElement.type)) { | ||
| iterableCaster = '.toSet()'; | ||
| } | ||
|
|
||
| return ''' | ||
| state.queryParametersAll[ | ||
| ${escapeDartString(parameterElement.name.kebab)}] | ||
| ?.map($entriesTypeMapper)$iterableCaster'''; | ||
| } | ||
| return ''' | ||
| state.queryParametersAll[${escapeDartString(parameterElement.name.kebab)}]'''; | ||
| } | ||
|
|
||
| @override | ||
| String _encode(String fieldName, DartType type) => fieldName; | ||
|
|
||
| @override | ||
| bool _matchesType(DartType type) => | ||
| const TypeChecker.fromRuntime(Iterable).isAssignableFromType(type); | ||
| } | ||
|
|
||
| abstract class _TypeHelperWithHelper extends _TypeHelper { | ||
| const _TypeHelperWithHelper(); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would be good to modulalize this to be a class. I imagine someone would like to do this
The idea is to be able to choose the query parameter name.
Uh oh!
There was an error while loading. Please reload this page.
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.
Hi @Skogsfrae WDYT about this? The main concern is the query parameter names are hardcoded which I imagine people would ask for customized query parameter names in the future. Although this is not something we have to fix now, but the current API, as it is written, may not be able the extend to support this feature.