Flutter/Dart developers, rejoice! If you've ever felt like your Dart code could use a sprinkle of performance magic, this extension is for you. It automatically adds the const
keyword to constructors and static methods where it’s missing.
- Performance:
const
objects are compile-time constants, which means they’re optimized at build time. Your app will thank you for the speed boost. - Cleaner Code: Fewer manual changes mean a cleaner codebase and less chance of missing crucial optimizations.
- Less Stress: No more worrying about those irritatating warnings — we’ve got you covered!
- Automatic Optimization: Adds
const
where applicable based on diagnostics. - Manual Trigger: Use the command palette to manually optimize your Dart code.
- On Save: Automatically optimize Dart files upon saving.
- Open VS Code.
- Go to Extensions (
Ctrl+Shift+X
on Windows orCmd+Shift+X
on Mac). - Search for
Flutter Const Optimizer
. - Click Install.
- Open the Command Palette (
Ctrl+Shift+P
on Windows orCmd+Shift+P
on Mac). - Type
Flutter Const Optimizer: Optimize Code
. - Press Enter.
- Voila! Your code will be optimized.
- Simply save your Dart file.
- The extension will automatically check for optimization opportunities and apply them.
The extension will show a notification for each optimization applied. If you have any issues or need to review changes, you’ll see relevant messages in the info panel.
- Diagnostics Check: The extension scans for Dart diagnostics suggesting
const
optimizations. - Text Analysis: It evaluates where
const
can be added. - Code Update: Applies the
const
keyword and saves your file automatically.
Before:
class MyClass {
MyClass();
}
void myMethod() {
MyClass();
}
After:
class MyClass {
const MyClass();
}
void myMethod() {
const MyClass();
}
- Issues: If you find any issues, please create a GitHub issue.
- Suggestions: I’d love to hear your feedback and suggestions to improve the extension!
Feel free to contribute to this project. Check out the contributing guidelines and get started!
Did you know? Adding const
can make your code faster and more memory-efficient. It’s like giving your Dart code a power-up!