difference between Reformat Code / Reformat Code with dartfmt - android-studio

In Android studio, when I open a dart file, I see two options to format the code, so my question is
What is the difference between Reformat Code / Reformat Code with dartfmt

Difference between them I don't know but I know how you can add a shortcut to format code:
Go to
File -> Settings -> Keymap -> Editor Action -> Reformate Code with dartfmt
and add click on it and add a shortcut

Both are the same essentially.
The only difference is that Reformat Code (ctrl + alt + L) applies only to the file open in the Editor or the file selected in project files pane using Intellij's Code formatter feature.
While Reformat Code using dartfmt uses dartfmt CLI command available with the flutter SDK.
The output of both will be the same. dartfmt allow you to format the code on directory level and from a cmd/terminal instead of an IDE.

**Automatically formatting code in Android Studio and IntelliJ
**
Install the Dart plugin to get automatic formatting of code in Android Studio and IntelliJ.
To automatically format the code in the current source code window, right-click in the code window and select Reformat Code with dartfmt. You can add a keyboard shortcut to this in Keymap section of IntelliJ Preferences.
You can also do it with
flutter format path1 path2 ...
(From terminal window)
Official link to flutter formatting tool
This shows that dartfmt is just a formatter by dart specifically for dart files. Default format code given by Android studio also could do this if file extension is identified by Android studio.

Related

How to enable word-wrap for editor in Android Studio on MacOS

Recently the Android Studio 3.5 updates and now Android Studio 3.6, the editor window does not wrap the text so some lines are long and go off the right of the screen. I don't want to scroll left and right all the time, so would like the text to autowrap. I've read many posts on the issue but nothings has solved it.
I've tried going to
Preferences -> Editor -> General and enabling soft wraps there, but that hasn't helped.
I tried adding *.java to the soft wraps files but that didn't help.
The only thing that works is selecting View -> Active Editor - Soft Wrap. That formats the current editing window with auto wrap, but each time I open a new java file auto wrap is not enabled I would need to enable it again. This is so frustrating and was never an issue before Android Studio 3.5. Any help would be appreciated.
I had the same problem, and my solution should work for you. The delimiter in the soft-wrap file list is a semicolon, not a comma: change your comma to a semicolon.

How to save dart file in file system with android studio generated comments?

I like how Android Studio and Visual Studio , generate the comments for each closing brackets, but when I open the same file in notepad++ or any other text editor, I don't see those comments. Is there a way to generate the saved dart file so it has those comments stored as part of the text code( in comment) ?
Here is one code example that how code looks in android studio.
but when opened with notepad it does not have the comment MaterialApp. I am guessing there is some settings in android studio that will let me save file with generated comments, so it can be useful outside of Android studio like in git etc.
These comments are generated "on the fly" by the Flutter plugin for Android Studio. At no time, these comments are inserted into your source files. They are just shown within the IDE. So I think there is no way to "export" these comments.

How to prevent auto formatting after moving files to another package in Android Studio?

Whenever I try to move file to another package, Android Studio reformats file's code structure to a different state.
For example such part of code:
doSomething(makeSomeParameters(value1, value))
becomes:
doSomething(
makeSomeParamaters(
value1,
value2
)
)
Notice that this line was not exceeding 100 columns constraint.
I use code style from official Kotlin style guide.
To configure the IntelliJ formatter according to this style guide,
please install Kotlin plugin version 1.2.20 or newer, go to Settings |
Editor | Code Style | Kotlin, click on "Set from…" link in the upper
right corner, and select "Predefined style / Kotlin style guide" from
the menu.
When you attempt to move a file to another package and Android Studio shows this dialog:
Uncheck the Update package directive check box; Android Studio will not reformat the code in the file.

Where is Android Studio Markdown support plugin preview preference?

I want to show preview for markdown.
But it is not shown.
I am using Markdown support by JetBrains. And Android Studio 3.1
I found IntelliJ help.
https://www.jetbrains.com/help/idea/markdown.html
But I can not see that preference.
How can I see markdown preview?
Updating JetBrains Runtime (JBR) will solve the issue.
Start the IDE, use Help -> Find Action, type "Choose Boot Java Runtime for the IDE", press Enter.
Select the newest version with JCEF to install.
Click the OK button and wait until the file with JetBrains Runtime is downloaded and configured.
Restart the IDE and Enjoy.
Video(44S): https://youtu.be/Mtu3dUgK480
Go to File>Preferences>Editor>File Types then select Files Opened In AssociatedApplications and add *.md to the list
Reassign the wild card
Do likewise for the Text file type
Enable the Markdown
Go with Vladimir Schneider
Preview like a bawse!
UPDATE: As mentioned by #desgraci below. It's now a paid plugin. It doesn't even show up. It would ideally work as indicated in the updated documentation but some requests left in the reviews.
I'm unable to make it work.
I suggest giving up and opening it in Visual Studio Code.
Right-click tab with your file, select Split Right.
In second instance, right-click tab again and select Open in Preview.
Now you have text and preview at the same time.
Taken from https://issuetracker.google.com/issues/159933628?pli=1#comment7
In the Android Studio:
Find action (ctrl + shift + A / command + shift + A)
Search for Choose Boot Java Runtime for the IDE
Select the latest version in
the "New:" dropdown - e.g. 11.0.12+7-b1504.27 JetBrains Runtime with
JCEF OK Restart
Worked in: Android Studio Chipmunk | 2021.2.1 Patch 1 | Build #AI-212.5712.43.2112.8609683
There is another plugin which is "Markdown Navigator Enhanced" and that I tested on Android Studio 3.5.2, it enables a toolbar with some editing functions as well as the preview options.
You can Edit, preview or do both in a split window, you can even show the HTML code.
The plug-in is paid, but it has a 30-days trial that can be good for a short usage.
Download plugin first,and then you'd better do something to active it:
Windows:
AndroidStudio ->File -> Editor ->Coe Style -> File Types->Markdown-> + -> *.md -> ok -> ok
Mac:
AndroidStudio -> Preferences -> Editor -> FileTypes -> Markdown-> + -> *.md -> ok -> ok
Then enjoy writing in md.
This is not just a JavaFX issue, which can be resolved by installing Choose Runtime plugin and choosing a different JDK. The Markdown plugin itself also references classes from IntelliJ UI, which means that even with a runtime that includes JavaFX, it still requires IntelliJ and won't work properly with Android Studio:
Caused by: java.lang.ClassNotFoundException: com.intellij.ui.javafx.JavaFxHtmlPanel PluginClassLoader[org.intellij.plugins.markdown, 193.6494.42] com.intellij.ide.plugins.cl.PluginClassLoader#4fa7c8ac
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:77)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 93 more
It will still work with the default bundled JDK, just reduced functionality without the preview panel.
References:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003498520-Mardown-plugin-doesn-t-show-preview
https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under
A little late but you can go to Settings/Preferences -> Editor -> File Types. Select Markdown Language from the list. Below, in the Registered Patterns section, add *.md, press ok, and restart Android Studio
Elijah's answer is great, but you may have to do ↓ after his actions.
Preferences -> Editor -> FileTypes -> Markdown-> + -> *.md
Since there is no good plugin for Android Studio IDE, If you have VS Code, I recommend Markdown Preview Enhanced plugins.
Or if you work a lot with Notepad++ , you can install the MarkdownViewerPlusPlus plugin
Follow folowing steps for Notepad++ MarkdownViewerPlusPlus plugin setup:
Download MarkdownViewerPlusPlus, you get a .dll file
Open notepad++ -> plugins -> open plugin folder
create subfolder "MarkdownViewerPlusPlus", paste your .dll file
restart notepad++, in plugins menu options now you should see MarkdownViewer++.
File -> Editor -> File Types->Markdown-> + -> *.md -> ok
File -> Editor -> File Types -> ASSOCIATE FILE TYPES WITH ANDROID STUDIO -> select all -> ok -> yes
File -> Plugins -> Marketplace -> search "Markdown" -> install -> APPLY -> OK
Help -> Find Action -> "Choose Boot Java Runtime for the IDE" -> Select the runtime that comes with JCEF support -> OK
restart Android Studio
My solution to this issue is to preview on VS Code
Go to File>Preferences>Editor>File Types then select Files Opened In AssociatedApplications and add *.md to the list
when you open the md file it will ask if you want to open it with your favorite file editor select vs code
Alternatively you can use markdown editors separately. Here are few options:
MacDown for Mac
Typora
GhostWriter
Few more online editors:
StackEdit
Dillinger
Editor.md
Draft
In the Android Studio:
Find action (ctrl + shift + A / command + shift + A)
Search for Choose Boot Java Runtime for the IDE
Select the latest version in the "New" dropdown - e.g.:
11.0.16.8-2043.64-jcef JetBrains Runtime with JCEF
OK
Restart
Worked in:
Android Studio Electric Eel | 2022.1.1
Build #AI-221.6008.13.2211.9477386, built on January 11, 2023

Using tab identation instead of spaces on Android Studio

Just trying to use tab-indentation on Android Studio 2.2.2
I followed the instructions I found on this thread:
Android Studio "This file is indented with tabs instead of 4 spaces"
But these instructions work only for new documents I create after setting that configuration but for previously created documents the space-indentation persists.
How can I configure all the files on my project to tab-indentation? for files before and after the tab-indentation configuration on the link above?
After changing the settings you have to reformat your codes, you can do this one by one by opening the file and pressing (Command + Option + L) shortcut or right click on your src folder and selecting Reformat Code option:
You can check the result by selecting View -> Active Editor -> Show Whitespaces from the menu:
which would be something like this:

Resources