-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[go_router_builder] Migrate to Element2 API and update dependencies #9649
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
base: main
Are you sure you want to change the base?
Conversation
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.
Code Review
This pull request migrates the go_router_builder
package to the Element2
API, updating dependencies and improving test code formatting. The changes are well-structured and consistently applied across the codebase. The migration to the new API is crucial for maintaining compatibility with the latest versions of analyzer
, build
, and source_gen
.
if (element.isRequired) { | ||
if (element.type.nullabilitySuffix == NullabilitySuffix.question && | ||
_pathParams.contains(element.name)) { | ||
_pathParams.contains(element.displayName)) { |
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.
@@ -60,14 +60,14 @@ class ShellRouteConfig extends RouteBaseConfig { | |||
|
|||
@override | |||
Iterable<String> classDeclarations() { | |||
if (routeDataClass.unnamedConstructor == null) { | |||
if (routeDataClass.unnamedConstructor2 == null) { |
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.
final String generated = formatter.format(results.join().replaceAll('\n', '')); | ||
final String expected = formatter.format(expectResult.replaceAll('\n', '')); | ||
expect(generated, equals(expected)); |
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.
Mac_arm64 custom_package_tests master and Mac_arm64 custom_package_tests stable are passed, but Windows_x64 custom_package_tests master is failed. |
Fix test code to support windows path separator. 96d68f9 |
} | ||
} | ||
|
||
InfoIterable _generateForAnnotatedElement( | ||
Element element, | ||
Element2 element, |
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.
looking at the doc https://pub.dev/documentation/analyzer/latest/dart_element_element/Element2.html
should we keep the original class name
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.
@chunhtai
Element2 will be deprecated starting with analyzer v8.0.0. Since analyzer: “>=7.4.0 <8.0.0”
is set, Element2 is not deprecated.
https://pub.dev/documentation/analyzer/7.7.1/dart_element_element2/Element2-class.html
https://pub.dev/documentation/analyzer/8.0.0/dart_element_element/Element2.html
Other libraries are also replacing Element2 in the same way.
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.
can we pin analyzer 8.0.0 and above directly?
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.
@chunhtai
It will be difficult as it was not announced in advance. Specifying ^8.0.0
will break compatibility with other packages.
https://github.com/dart-lang/mockito/blob/v5.4.5/pubspec.yaml
https://github.com/google/json_serializable.dart/blob/json_serializable-v6.10.0/json_serializable/pubspec.yaml
https://github.com/rrousselGit/freezed/blob/freezed-v3.2.0/packages/freezed/pubspec.yaml
final String routeData = _annotations[type]!; | ||
if (element is! ClassElement) { | ||
if (element is! ClassElement2) { |
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.
throw InvalidGenerationSourceError( | ||
'The ShellRouteData "$_className" class must have an unnamed constructor.', | ||
element: routeDataClass, | ||
); | ||
} | ||
|
||
final bool isConst = routeDataClass.unnamedConstructor!.isConst; | ||
final bool isConst = routeDataClass.unnamedConstructor2!.isConst; |
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.
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.
and all other places
@chunhtai https://github.com/dart-lang/source_gen/blob/source_gen-v3.0.0/source_gen/pubspec.yaml |
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
close flutter/flutter#170832
close flutter/flutter#171003
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assist
bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3