Skip to content

Extract variable action should have a final option #6304

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

Open
widarlein opened this issue Sep 13, 2022 · 2 comments
Open

Extract variable action should have a final option #6304

widarlein opened this issue Sep 13, 2022 · 2 comments

Comments

@widarlein
Copy link

Hi! I'm a heavy user of keyboard shortcuts when I work in Android Studio, but for flutter code this is somewhat lacking imo. When I preform the procedure below, I would almost always change the "var" to "final" because it's usually more useful. What I would prefer is that this action produces a final, but there could also be an alternative action for final.

Other than that there's a lot of useful actions, many of them can be found in Settings->Keymap under Main Menu-->Refactor-->Extract/Introduce. The below mentioned action is called Introduce Variable, but other useful ones are Introduce Field, Extract Method et al. It would be really cool if these were supported when coding flutter.

Great work people! Loving flutter!

Steps to Reproduce

  1. Be in a function scope.
  2. type 123.toString();
  3. place the caret somewhere within toString()
  4. Either
    • press ctrl+alt+v
    • alt+Enter and choose "Assign value to new local variable"
  5. Line turns into var string = 123.toString();

Version info

[√] Flutter (Channel stable, 3.0.3, on Microsoft Windows [Version 10.0.19044.1889], locale en-SE)
    • Flutter version 3.0.3 at E:\Development\sdks\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 676cefaaff (3 months ago), 2022-06-22 11:34:49 -0700
    • Engine revision ffe7b86a1e
    • Dart version 2.17.5
    • DevTools version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
    • Android SDK at E:\Development\Android\Sdk
    • Platform android-31, build-tools 33.0.0-rc4
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)

[√] IntelliJ IDEA Community Edition (version 2021.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.2
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] VS Code, 64-bit edition (version 1.62.0-insider)
    • VS Code at C:\Program Files\Microsoft VS Code Insiders
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1889]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 105.0.5195.102
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 105.0.1343.27
    ! Device emulator-5556 is offline.

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
@stevemessick
Copy link
Member

It seems like the Dart analyzer ought to be able to determine that a declaration should be var if its redefined, final it is isn't, and const if it is a constant (not sure about that last).

@bwilkerson
Copy link

Addition conversation in dart-lang/sdk#50018.

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

No branches or pull requests

3 participants