Skip to content

The-Sirius-Black/dart-spells.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DART-SPELLS

dart-spells is a Neovim plugin designed to help Flutter development.

Installation

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,
}

Requirements

Some features of the Dart Spells plugin, as well as planned future features, require the dart-spells.

Current Features Requiring dart-spells:

  • copyWith
  • props

Features

1. Copy with

Generate a copyWith method for the class under your cursor.

require("dart-spells").copy_with()

2. Props

Generate a props getter for the class under your cursor.

require("dart-spells").props()

3. Widget Wrapping

Predefined Functions

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()

Custom Widget Wrapping

The plugin provides two functions: wrap_with_widget and wrap_with_builder.

wrap_with_widget

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.

How It Works

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.

Example

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!"
        )
    )
)

Important Note

  • 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!"
        )
    )
)

wrap_with_builder

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.

How It Works

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.

Example

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!"
            )   
        ),
    },
);

Important Note

  • 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!"
            )
        ),
    }
)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages