Reformat Dart code on save

Your dart code can become a huge Bracket puzzle and also an unreadable one if it's not properly formatted. I call it a Bracket puzzle because it may be a little confusing to find the bracket you forgot to write in unreadable code.

We are talking about converting this

Center(child: AnimatedContainer(duration: Duration(milliseconds: 100), height: 300, width: 20, decoration: BoxDecoration(color: Colors.deepPurple),),

To —- — -— — ⬇️ — — — — This

Center(  
child: AnimatedContainer(
duration: Duration(milliseconds: 100),
height: 300,
width: 20,
decoration: BoxDecoration(color: Colors.deepPurple),
),

There is a handy shortcut available for this. It’s Ctrl + Alt + R(PC) | ⌃ + ⌥ + R(Mac) in Android Studio but who likes to do this every time when you write code??

There is one option called ‘Format code on Save’ in the Android studio’s settings page which reformats code when you save. Isn’t it exciting?

Here are steps to enable it in Android studio.

Press enter or click to view image in full size
  1. Go to settings.
  2. Click on Language and Framework section.
  3. Choose Flutter.
  4. Now you will find an option in the editor section.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

How to extract filename from Uri?

Now, we can extract filename with and without extension :) You will convert your bitmap to uri and get the real path of your file. Now w...