skip to Main Content

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

4

Answers


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

    Login or Signup to reply.
    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.
    Login or Signup to reply.
  2. As of my knowledge we have to manually add const keyword where we want…

    Login or Signup to reply.
  3. You can do that by running the following command:

    dart fix --apply
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search