Safe Emit for Bloc is a VSCode extension that automatically wraps emit calls in bloc state management with a safeEmit method. This extension helps prevent common issues related to emitting states in bloc patterns, ensuring more robust and predictable state management in your Flutter applications.
- Automatically detects
emitcalls in your bloc files - Wraps detected
emitcalls withsafeEmitmethod - Supports single-line and multi-line
emitstatements - Configurable through VSCode settings
For example if there is an image subfolder under your extension project workspace:
- Open VSCode
- Go to the Extensions view (Ctrl+Shift+X)
- Search for "Safe Emit for Bloc"
- Click Install
Once installed, the extension will automatically wrap any emit calls in your bloc files with safeEmit. For example:
Before:
emit(SomeState());After:
safeEmit(() => emit(SomeState()));
The extension works on save, so simply save your file to see the changes applied.
You can configure the extension's behavior in your VSCode settings:
- safeEmit.enabled: Enable or disable the extension (default: true)
- safeEmit.fileTypes: Array of file extensions to apply the transformation (default: [".dart"])
- safeEmit.ignoredFolders: Array of folder names to ignore (default: ["test", "spec"])
- VSCode 1.60.0 or higher
- Dart and Flutter extensions for VSCode
May conflict with other code formatting extensions. It's recommended to run this extension last in your formatting pipeline.
Contributions are welcome! Please feel free to submit a Pull Request.
This extension is released under the MIT License.
If you encounter any issues or have feature requests, please file them in the issues section on GitHub.
