Skip to content
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

Use super-initializer parameter in live templates #6398

Closed
wants to merge 2 commits into from
Closed

Use super-initializer parameter in live templates #6398

wants to merge 2 commits into from

Conversation

MrLightful
Copy link

To avoid having to manually pass each parameter into the super invocation of a constructor, you can use super-initializer parameters to forward parameters to the specified or default superclass constructor. This produces cleaner classes.

This PR thus updates live templates to use them instead.

Language Tour | Dart -- Constructors
Language Tour | Dart -- Design

Addresses: #6071

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read the Flutter Style Guide recently, and have followed its advice.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@stevemessick
Copy link
Member

Thanks for the PR. Unfortunately, this won't work for older versions of the Dart SDK. There are many projects that have not migrated to null-safety yet, so they are still using Flutter 2.12 or so. This change requires Flutter 3.0 or newer. Also, we don't edit the XML file; it is generated (see below).

If you want to make this change, modify FlutterLiveTemplatesProvider to check the Flutter SDK version and return a file that works for that version. Unfortunately, getting the SDK version will be difficult, as it depends on the current Project. There may be multiple projects open and each could have its own SDK version. I think it can be done using the IntelliJ WindowManager API. (You'd need to find the top-most JFrame then query it for its project.) You'd also need to do some work in the tool/plugin plugin-management tool. It has a generate command that generates the live template file from the templates (*.txt). It would need to be extended to generate both forms.

Ideally, we'd ask the Dart analysis server to provide the live templates. It knows the SDK version so could provide the proper form. There's been some talk about adding that feature to the LSP API, but the Flutter plugin does not use LSP, so that won't actually help us. Unless we hook up the LSP version, too, which isn't on anyone's radar currently.

@stevemessick
Copy link
Member

@romatallinn Do you plan to do any more work on this PR? If not, I'll close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants