Home > Enterprise >  Add auto-Const in flutter in Android Studio
Add auto-Const in flutter in Android Studio

Time:04-15

I have switched from vsCode to android studio for my flutter project as I think I feel comfortable reading the code In android studio

Though in vs code when i save the file the file gets formatted and it adds const keyword wherever my widget needed it

PROBLEM

In android studio neither the code gets formatted nor it adds const keyword wherever its needed

Please help with the 2 problem

CodePudding user response:

  1. Go to File -> Settings -> Languages & Frameworks -> Flutter
  2. Under Editor Section check the Format code on save and Organize imports on save options and Apply changes.

CodePudding user response:

You can use macros for formatting and saving the document with just one shortcut

Record the macro

  • Open any file in the editor.
  • From the main menu, select Edit | Macros | Start Macro Recording.
  • Press ⌥⌘L to reformat code (Code | Reformat Code ).
  • Then press ⌘S to save all changes (File | Save All ). Android
    Studio/IntelliJ IDEA will show the performed actions in the status
    bar.
  • Stop recording by selecting Edit | Macros | Stop Macro Recording.
  • In the Enter Macro Name dialog, specify the name for the new macro and click OK.

BIND THE MICRO WITH SHORTCUT

  • In the Settings/Preferences dialog ⌘,,

  • select Keymap.Expand the Macros node and select the created Reformat and Save macro.

  • Right-click the macro and choose Add Keyboard Shortcut in the context menu

enter image description here

  • Related