Abdul raheem
Abdul raheem

Reputation: 195

Add auto-Const in flutter in Android Studio

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

Upvotes: 5

Views: 5270

Answers (5)

Taher Salah
Taher Salah

Reputation: 427

You must follow these steps :-

1- Go to File Settings Languages & Frameworks Flutter

enter image description here

2- check the Format code on save and Organize imports on save options and Apply changes.

enter image description here

4- running the following command:dart fix --apply

enter image description here

5- res =>

after

enter image description here

before 

enter image description here

Upvotes: 1

Bensal
Bensal

Reputation: 4120

You can do that by running the following command:

dart fix --apply

Upvotes: 5

harizh
harizh

Reputation: 386

As of my knowledge we have to manually add const keyword where we want...

Upvotes: 1

Dulaj Nadawa
Dulaj Nadawa

Reputation: 603

  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.

Upvotes: 8

AKA
AKA

Reputation: 11

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

Upvotes: 1

Related Questions