Create Flutter boilerplate code with fewer typing with Android Studio Custom Live Templates
Flutter requires developers to write many boilerplate codes. Android Studio provides a way to solve the problem, which is Live Templates. Live templates allow you to use customized shorthand to write repetitive boilerplate codes. This article will show you how to use Live Templates to minimize the effort to write repeated code.
The image below shows how Live Templates work in Android Studio:
Creating Live Templates
Here are the steps to create Live Templates:
1. start Android Studio
2. open Live Templates Preferences (Editor |Live Templates)
3. create Live Template Group
4. select the new template group
5. create a Live Template
6. add abbreviation (the shorthand that you want to use)
7. add a description (optional)
8. add template text
9. define a context (Dart |Top Level)
10. Save the template
The result should look like the image below:
Live Templates contain variables that allow you to replace with values you can type or with a default value. For example
$view$ . Edit variables allow customization to the variables. The image below shows the window of the Edit Template Variables:
Android Studio provides functions in the Expression tab to make variables more usable. Here is a list of functions that you may find useful:
Sharing Live Templates
Android Studio provides a way for you to share live templates with your teammates or different machines. Open Settings Repository (File | Manage IDE Settings | Settings Repository). Set the remote repository to sync settings with the IDE.
Flutter Enhancement Suite
Flutter Enhancement Suite is an Android Studio plugin that provides useful live templates. You can see more information on this link.
If you have finished this article, thank you I hope you will find it useful. If you find this article is so much shorter than my usual articles. It is because I’m practicing my technical writing with this course. And it is not as easy as I thought.
On the other note, if you want to work for a company that is:
- The leader in the 3D body-scanning industry.
- Collaborate and grow the company with tremendously smart and talented software developers in different skills.
- You love working with the latest cutting edge technology like ARCore, Flutter, ARKit and so on.
Join us via using this link to submit your application and interest!