A Neovim plugin for generating bloc and cubit boilerplate code with support for code actions.
Screen.Recording.2024-03-03.at.8.36.46.PM.mov
- Generate bloc boiler plate code
- Generate cubit boiler plate code
- Code actions
- With lazy.nvim
{
'wa11breaker/flutter-bloc.nvim',
dependencies = {
"nvimtools/none-ls.nvim", -- Required for code actions
},
opts = {
bloc_type = 'default', -- Choose from: 'default', 'equatable', 'freezed'
use_sealed_classes = false,
enable_code_actions = true,
}
}
- With packer.nvim
use {
'wa11breaker/flutter-bloc.nvim',
requires = {
'nvimtools/none-ls.nvim',
},
config = function()
require('flutter-bloc').setup({
bloc_type = 'default', -- Choose from: 'default', 'equatable', 'freezed'
use_sealed_classes = false,
enable_code_actions = true,
})
end
}
Note
Currently doesn't support plugin invocation from tree explorer to generate bloc inside a folder. You will get 'attempt to concatenate local 'buf_directory' (a nil value)' as the buf_direcotry will be nil.
-
bloc_type
: Specifies the type of BLoC generation'default'
: Standard BLoC generation'equatable'
: Uses Equatable for equality comparisons'freezed'
: Generates code with Freezed immutable classes
-
use_sealed_classes
: Enables or disables sealed classes generation
Commands
:FlutterCreateBloc
- Create a new Bloc:FlutterCreateCubit
- Create a new Cubit
Code Actions
- Wrap with
BlocBuilder
- Wrap with
BlocSelector
- Wrap with
BlocListener
- Wrap with
BlocConsumer
- Wrap with
BlocProvider
- Wrap with
RepositoryProvider
You can add custom key mappings to streamline your workflow:
-- Create BLoC quickly
vim.keymap.set("n", "<Leader>cfb", "<cmd>lua require('flutter-bloc').create_bloc()<cr>", {
desc = '[C]reate [F]lutter [B]loc'
})
-- Create Cubit quickly
vim.keymap.set("n", "<Leader>cfc", "<cmd>lua require('flutter-bloc').create_cubit()<cr>", {
desc = '[C]reate [F]lutter [C]ubit'
})
For detailed documentation and advanced usage, refer to the help file:
:help flutter-bloc.nvim