Skip to content

[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

Merged
merged 9 commits into from
Aug 13, 2025

Conversation

koji-1009
Copy link
Contributor

@koji-1009 koji-1009 commented Jul 19, 2025

close flutter/flutter#170832
close flutter/flutter#171003

  • Update build, build_test, and source_gen versions.
  • Update analyzer version to support Element2 API.
  • Fix unit test code formatting and comparison logic
  • Flutter 3.29 and Dart 3.7.

Pre-Review Checklist

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

  1. 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

Copy link

@gemini-code-assist gemini-code-assist bot left a 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)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The migration to Element2 API involves changes to how parameter names are accessed. Ensure that the display name is correctly used throughout the codebase to maintain consistency and prevent unexpected behavior.

@@ -60,14 +60,14 @@ class ShellRouteConfig extends RouteBaseConfig {

@override
Iterable<String> classDeclarations() {
if (routeDataClass.unnamedConstructor == null) {
if (routeDataClass.unnamedConstructor2 == null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The migration to Element2 API involves changes to how constructor elements are accessed. Consider updating the error message to reflect the new API usage and improve clarity for developers debugging potential issues related to constructor access.

Comment on lines 60 to 62
final String generated = formatter.format(results.join().replaceAll('\n', ''));
final String expected = formatter.format(expectResult.replaceAll('\n', ''));
expect(generated, equals(expected));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comparison logic has been updated to improve robustness against formatting variations. Consider adding a comment explaining why the replaceAll calls are necessary to improve code understanding and maintainability.

@koji-1009
Copy link
Contributor Author

@koji-1009 koji-1009 marked this pull request as ready for review July 21, 2025 02:39
@koji-1009 koji-1009 requested a review from chunhtai as a code owner July 21, 2025 02:39
@koji-1009
Copy link
Contributor Author

koji-1009 commented Jul 21, 2025

Fix test code to support windows path separator. 96d68f9

}
}

InfoIterable _generateForAnnotatedElement(
Element element,
Element2 element,
Copy link
Contributor

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

Copy link
Contributor Author

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.

google/json_serializable.dart#1504
rrousselGit/freezed#1276

Copy link
Contributor

@chunhtai chunhtai Jul 30, 2025

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?

Copy link
Contributor Author

@koji-1009 koji-1009 Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final String routeData = _annotations[type]!;
if (element is! ClassElement) {
if (element is! ClassElement2) {
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and all other places

@koji-1009 koji-1009 requested a review from chunhtai July 30, 2025 21:49
@koji-1009
Copy link
Contributor Author

@chunhtai
I think it is better for go_router_builder to specify analyzer ^7.4.0, at least until source_gen starts specifying analyzer ^8.0.0.

https://github.com/dart-lang/source_gen/blob/source_gen-v3.0.0/source_gen/pubspec.yaml

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chunhtai chunhtai requested a review from hannah-hyj August 1, 2025 19:16
@muhammadkamel
Copy link

@hannah-hyj
Waiting for your review. Thanks!

Copy link
Member

@hannah-hyj hannah-hyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevmoo
Copy link
Contributor

kevmoo commented Aug 13, 2025

Thank you! 🙏

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 13, 2025
@auto-submit auto-submit bot merged commit 6cb9113 into flutter:main Aug 13, 2025
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 13, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Aug 13, 2025
flutter/packages@08a9b2c...6cb9113

2025-08-13 [email protected] [go_router_builder] Migrate to
Element2 API and update dependencies (flutter/packages#9649)

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 [email protected] 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
@koji-1009 koji-1009 deleted the feat/element2 branch August 13, 2025 22:13
CaoGiaHieu-dev added a commit to CaoGiaHieu-dev/packages that referenced this pull request Aug 14, 2025
* main: (56 commits)
  [go_router_builder] Support extension types (flutter#9458)
  Roll Flutter from e2a347b14a18 to 34c2a3b158b2 (41 revisions) (flutter#9803)
  [go_router_builder] Migrate to Element2 API and update dependencies (flutter#9649)
  [in_app_purchase_storekit] Add support for quantity in consumable product purchases (#171570) (flutter#9698)
  [pigeon] Improves documentation of `ProxyApi` and moves helper functions to a separate file (flutter#9756)
  Roll Flutter from 1590543f6794 to e2a347b14a18 (1 revision) (flutter#9784)
  [camera_avfoundation] Implementation swift migration - part 11 (flutter#9690)
  [camera_avfoundation] Fix crash when streaming while recording (flutter#9691)
  Roll Flutter from 38217906e95c to 1590543f6794 (14 revisions) (flutter#9780)
  Roll Flutter from 92a6bfbfd6ef to 38217906e95c (17 revisions) (flutter#9778)
  [video_player] Improve KVO handling on iOS (flutter#9718)
  [dependabot]: Bump the test-dependencies group across 15 directories with 7 updates (flutter#9736)
  Roll Flutter from 9de63a03428f to 92a6bfbfd6ef (11 revisions) (flutter#9769)
  [google_maps_flutter_platform_interface] Add Advanced markers support (flutter#9737)
  [camera_android_camerax] Re-land "Force new Surface for each SurfaceRequest" (flutter#9760)
  [google_maps_flutter] Add ability to perform Google Maps SDK warmup (flutter#9674)
  Roll Flutter from 59fc766c6fdf to 9de63a03428f (6 revisions) (flutter#9764)
  [webview_flutter_wkwebview] Extended Web View API on iOS to add flexibility when working with local HTML content (flutter#8787)
  [local_auth] Differentiate iOS authentication errors (flutter#9705)
  manual roll to 59fc766c6fdfd03d0983fc95ce8b76793a300dd5 (flutter#9758)
  ...

# Conflicts:
#	packages/go_router_builder/lib/src/type_helpers.dart
#	packages/go_router_builder/pubspec.yaml
SydneyBao pushed a commit to SydneyBao/flutter that referenced this pull request Aug 14, 2025
…#173726)

flutter/packages@08a9b2c...6cb9113

2025-08-13 [email protected] [go_router_builder] Migrate to
Element2 API and update dependencies (flutter/packages#9649)

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 [email protected] 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: go_router_builder
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[go_router_builder] ClassElement is deprecated [go_router_builder] Update to build_test 3.x
5 participants