Tip Code Faster
Last updated
Last updated
In the field of application development, speeding up the coding process not only saves time but also enhances work efficiency and product quality. Coding faster does not mean reducing code quality. Here, I will present the methods I use to make coding large Flutter applications easier while also facilitating maintenance and debugging.
To build large projects, writing a huge amount of code is inevitable. Instead of trying to reduce the workload unrealistically, you should focus on reducing coding time.
Mason is a powerful tool that automates source code generation. It allows you to create reusable code templates, helping to reduce the time spent writing repetitive code segments. By setting up code bricks (templates), you can quickly generate components like widgets, screens, or even an entire project structure with just a few simple commands.
Mason does not only generate code for Dart; you can also use it with other languages. Refer to my article about Mason to understand how it works and its applications in my work.
Libraries like json_serializable and build_runner allow you to automatically generate code from objects, which is especially useful when working with JSON. Instead of manually writing toJson
and fromJson
methods, you only need to define your model, and the library will handle the rest. This not only saves time but also reduces human errors.
If you know how to combine it with Mason, you can create objects with full functionality you need, such as copyWith
or equality comparison. You can refer to my two code samples at https://brickhub.dev/bricks/dr_entity and https://brickhub.dev/bricks/dr_freezed.
flutter_gen_runner
flutter_gen_runner helps automatically generate code for resources like images, fonts, and strings. Instead of remembering and typing the exact paths to each resource, you can safely and quickly access them through pre-generated variables. This helps minimize errors and speeds up the coding process. You can learn more in my article about creating a UI package here:
Below are the shortcuts I often use in Android Studio. Using these shortcuts makes programming feel a bit easier:
Normal
Shift+F10
Control+R
Run
Shift+F9
Control+D
Debug
Control+Space
Control+Space
Displays basic suggestions for variables, types, methods, expressions, and so on. If you call basic completion twice in a row, you see more results, including private members and non-imported static members.
Control+Tab
Control+Tab
Switch between tabs and tool window
Press Shift twice
Press Shift twice
Search everything (including code and menus)
Control+F
Command+F
Find
F3
Command+G
Find next
Shift+F3
Command+Shift+G
Find previous
Control+R
Command+R
Replace
Control+Shift+F
Command+Shift+F
Find in path
Control+F12
Command+F12
Open file structure dialog
Shift+F4
Shift+F4
Open current editor tab in new window
Control+E
Command+E
Recently opened files dialog
Control+Shift+E
Command+Shift+E
Recently edited files dialog
Control+G
Command+L
Go to line
Write code
Alt+Insert
Command+N
Generate code (getters, setters, constructors,hashCode/equals,toString, new file, new class)
Control+O
Control+O
Override methods
Control+I
Control+I
Implement methods
Control+Alt+T
Command+Option+T
Surround with (if...else,try...catch, etc.)
Control+Y
Command+Delete
Delete line at caret
Control+D
Command+D
Duplicate current line or selection
Control+Space
Control+Space
Basic code completion
Control+Shift+Space
Control+Shift+Space
Smart code completion (filters the list of methods and variables by expected type)
Control+Q
Control+J
Quick documentation lookup
F11
F3
Toggle bookmark
Control+F11
Option+F3
Toggle bookmark with mnemonic
Control+/
Command+/
Comment/uncomment with line comment
Control+Shift+/
Command+Shift+/
Comment/uncomment with block comment
Control+W
Option+Up -> Option+W
Select successively increasing code blocks
Control+Shift+W
Option+Down
Decrease current selection to previous state
Control+Alt+L
Command+Option+L
Reformat code
Control+Alt+I
Control+Option+I
Auto-indent lines
Control+Shift+J
Control+Shift+J
Smart line join
Control+Enter
Command+Enter
Smart line split
Shift+Enter
Shift+Enter
Start new line
F2 or Shift+F2
F2 or Shift+F2
Next/previous highlighted error
Debug
Shift+F9
Control+D
Debug
F8
F8
Step over
Refecter
Shift+F6
Shift+F6
Rename
Control+Alt+V
Command+Option+V
Extract variable
Git
Alt+` (backtick)
Control+V
Open VCS dialog
Using these shortcuts will help you minimize typing time and focus more on the application's code logic. You can learn more at Learn more
You may be familiar with stfull
or stless
in Flutter to create Stateful and Stateless widgets. You can also create your own code templates by creating live templates in your Android Studio IDE. Go to File > Settings > Editor > Live Templates in Android Studio to try creating one for yourself.
AI has become extremely useful for developers, significantly reducing the workload. Here are some applications of AI in my daily work:
Language Translation: Refer to my article on using multiple languages below.
Creating Basic Functions Using Algorithms
Optimizing Code Functions with Better Algorithms
Generating Automatic Code Functions
During development, some features take a lot of time to complete or test. By creating buttons or shortcuts to skip or simulate the results of these features, you can easily test the rest of the application without interruption. Previously, I developed a Bluetooth communication application where waiting for the returned results was time-consuming. I created buttons in the development environment to simulate receiving the results from the device via Bluetooth. This helped me significantly reduce the time spent on development. If you want to know how to create development, staging, and production environments, please refer to my article here:
One idea I find useful is displaying logs on the screen using these test buttons. This is effective when your device is not in debug mode, or backend developers can use the app and check logs without needing you to debug to see the logs. This helps reduce your workload. However, this will be more effective on larger screens like tablets. If you want to create color-coded logs like this, check out my article here:
These are the methods I use to code faster and make coding easier. If you have your own great methods, please share and contribute to the community.
I built the website using AI. It helped me quickly and efficiently write functions to retrieve data from Firebase, saving a substantial amount of research time. AI has tremendously reduced the time spent on learning and setup.
|