dart-spells
is a Neovim plugin designed to help Flutter development.
To install dart-spells
, use your favorite plugin manager.
Example using Lazy:
return {
"The-Sirius-Black/dart-spells.nvim",
config = function()
local spells = require("dart-spells")
vim.keymap.set("n", "key", spells.copy_with, {})
vim.keymap.set("n", "key", spells.wrap_with_bloc_builder, {})
vim.keymap.set("n", "key", spells.wrap_with_bloc_consumer, {})
vim.keymap.set("n", "key", spells.wrap_with_bloc_listener, {})
vim.keymap.set("n", "key", spells.wrap_with_bloc_provider, {})
vim.keymap.set("n", "key", spells.wrap_with_multi_bloc_provider, {})
-- vim.keymap.set("n", "key", spells.wrap_with_builder(replacment_text, callback), {})
-- vim.keymap.set("n", "key", spells.wrap_with_widget(replacment_text, callback), {})
end,
}
Some features of the Dart Spells plugin, as well as planned future features, require the dart-spells.
Current Features Requiring dart-spells
:
- copyWith
- props
Generate a copyWith
method for the class under your cursor.
require("dart-spells").copy_with()
Generate a props
getter for the class under your cursor.
require("dart-spells").props()
The plugin includes several predefined functions to assist with using Bloc.
These functions allow quick wrapping of widgets with Bloc widgets.
The available functions are:
require("dart-spells").wrap_with_bloc_builder()
require("dart-spells").wrap_with_bloc_consumer()
require("dart-spells").wrap_with_bloc_listener()
require("dart-spells").wrap_with_bloc_provider()
require("dart-spells").wrap_with_multi_bloc_provider()
The plugin provides two functions: wrap_with_widget
and wrap_with_builder
.
The wrap_with_widget
function allows you to wrap a selected widget with a specified widget structure. It takes two parameters:
- replacement_text: A string that specifies the structure to use for wrapping the selected widget code.
- callback: (Optional) A callback function that can be used to perform additional operations after wrapping.
The replacement_text
parameter only affects the portion of the code that is wrapped. It does not alter any other parts of the widget code outside of the wrapping structure.
Consider the following code:
Container(
child: Text(
"Hello, World!"
)
)
The function returns widget above wrapped as a child whose parent is your replacement string parameter.
For example:
If a replacement_text
is "MyWidget("
, the resulting code will look like this:
MyWidget(
child: Container(
child: Text(
"Hello, World!"
)
)
)
- The function will automatically add the closing bracket and the
child:
keyword. The rest of the code is up to you to fill in as needed.
child: Container(
child: Text(
"Hello, World!"
)
)
)
The wrap_with_builder
function allows you to wrap a selected widget with a specified builder structure. It takes two parameters:
- replacement_text: A string that specifies the structure to use for wrapping the selected widget code.
- callback: (Optional) A callback function that can be used to perform additional operations after wrapping.
The replacement_text
parameter only affects the portion of the code that is wrapped. It does not alter any other parts of the widget code outside of the wrapping structure.
Consider the following widget code:
Container(
child: Text(
"Hello, World!"
)
)
If a replacement_text
is "BlocBuilder(builder: (context,state) {"
, the resulting code will look like this:
BlocBuilder(
builder: (context,state) {
return Container(
child: Text(
"Hello, World!"
)
),
},
);
- The function will automatically add the closing bracket and the
return
keyword. The rest of the code is up to you to fill in as needed.
return Container(
child: Text(
"Hello, World!"
)
),
}
)