Skip to content

Commit b9ba40d

Browse files
committed
feat: Add "Wrap with RepaintBoundary" command
This commit adds a new command, "Wrap with RepaintBoundary", to the Flutter development extension. The command allows users to easily wrap any widget with a `RepaintBoundary` widget, which isolates the repaint process of the wrapped widget. This can improve performance in complex UIs. Note: This commit message follows the established convention of using a "feat" prefix for new feature additions.
1 parent 52290a7 commit b9ba40d

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

CONTRIBUTING.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## How to add widget wrappper
44

5-
1. Add command to package.json
5+
1. Add command to `package.json`
66

77
```json
88
{
@@ -17,7 +17,7 @@
1717
}
1818
```
1919

20-
2. Add snippet to src/commands/wrap-with.command.ts
20+
2. Add snippet to `src/commands/wrap-with.command.ts`
2121

2222
```ts
2323
const snippetListenableBuilder = (widget: string) => {
@@ -32,7 +32,18 @@ export const wrapWithListenableBuilder = async () =>
3232
wrapWith(snippetListenableBuilder);
3333
```
3434

35-
3. Add command to src/extension.ts
35+
3. Add action to `src/code-actions/code-action-wrap.ts`
36+
37+
```ts
38+
return [
39+
{
40+
command: "flutter-plus.wrap-listenablebuilder",
41+
title: "Wrap with ListenableBuilder",
42+
}
43+
]
44+
```
45+
46+
4. Add command to `src/extension.ts`
3647

3748
```ts
3849
export function activate(context: vscode.ExtensionContext) {

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
Extension add some useful commands to Flutter development in Visual Studio Code.
44

5+
## Wrap with...
6+
7+
This package extends your Flutter development experience by providing convenient snippets and commands for wrapping widgets with other commonly used Flutter widgets, similar to the "Wrap with..." functionality in Flutter's built-in extension for VS Code. These additions streamline the process of encapsulating your widgets within other widgets that enhance functionality or control, such as state management, repaint isolation, and more.
8+
9+
Simply select the widget you want to wrap, and choose the appropriate "Wrap with..." command from the command palette, or use the provided snippets to quickly insert the desired wrapper code into your widget tree.
10+
11+
- **Wrap with ListenableBuilder**: Easily wrap any widget with a `ListenableBuilder` to rebuild the widget based on changes in a `Listenable` object.
12+
- **Wrap with ValueListenableBuilder<T>**: Automatically wrap your widget with a `ValueListenableBuilder` to react to changes in a `ValueListenable<T>`.
13+
- **Wrap with RepaintBoundary**: Encapsulate your widget within a `RepaintBoundary` to isolate its repaint process, improving performance in complex UIs.
14+
15+
516
## Markdown snippets
617

718
| Shortcut | Description |
@@ -89,4 +100,4 @@ Extension add some useful commands to Flutter development in Visual Studio Code.
89100
| col | Creates a `Column` widget, which displays its children in a vertical array. |
90101
| wrap | Creates a `Wrap` widget, which displays its children in multiple horizontal or vertical runs, wrapping to the next line when necessary. |
91102
| stack | Creates a `Stack` widget, which allows you to place widgets on top of each other in a z-order. |
92-
| fittedbox | Creates a `FittedBox` widget, which scales and positions its child within itself according to the specified fit. |
103+
| fittedbox | Creates a `FittedBox` widget, which scales and positions its child within itself according to the specified fit. |

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
{
4747
"command": "flutter-plus.wrap-valuelistenablebuilder",
4848
"title": "Wrap with ValueListenableBuilder<T>"
49+
},
50+
{
51+
"command": "flutter-plus.wrap-repaintboundary",
52+
"title": "Wrap with RepaintBoundary"
4953
}
5054
],
5155
"submenus": [

src/code-actions/code-action-wrap.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { CodeAction, CodeActionKind, CodeActionProvider, window } from "vscode";
44
import { getSelectedText } from "../utils";
55

66
export class CodeActionWrap implements CodeActionProvider {
7-
87
public provideCodeActions(): CodeAction[] {
98
const editor = window.activeTextEditor;
109
if (!editor) return [];
@@ -22,6 +21,10 @@ export class CodeActionWrap implements CodeActionProvider {
2221
title: "Wrap with ValueListenableBuilder<T>",
2322
},
2423
/* TODO: Convert between ListenableBuilder <--> ValueListenableBuilder */
24+
{
25+
command: "flutter-plus.wrap-repaintboundary",
26+
title: "Wrap with RepaintBoundary",
27+
}
2528
].map((c) => {
2629
let action = new CodeAction(c.title, CodeActionKind.Refactor);
2730
action.command = {

src/commands/wrap-with.command.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ const snippetValueListenableBuilder = (widget: string) => {
1616
)`;
1717
};
1818

19+
const snippetRepaintBoundary = (widget: string) => {
20+
return `RepaintBoundary(
21+
child: ${widget},
22+
)`;
23+
};
24+
1925
export const wrapWithListenableBuilder = async () => wrapWith(snippetListenableBuilder);
2026

21-
export const wrapWithValueListenableBuilder = async () => wrapWith(snippetValueListenableBuilder);
27+
export const wrapWithValueListenableBuilder = async () => wrapWith(snippetValueListenableBuilder);
28+
29+
export const wrapWithRepaintBoundary = async () => wrapWith(snippetRepaintBoundary);

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import {
99
sealedStates,
1010
wrapWithListenableBuilder,
11+
wrapWithRepaintBoundary,
1112
wrapWithValueListenableBuilder,
1213
} from "./commands";
1314

@@ -27,6 +28,7 @@ export function activate(context: vscode.ExtensionContext) {
2728
commands.registerCommand("flutter-plus.sealed-states", sealedStates),
2829
commands.registerCommand("flutter-plus.wrap-listenablebuilder", wrapWithListenableBuilder),
2930
commands.registerCommand("flutter-plus.wrap-valuelistenablebuilder", wrapWithValueListenableBuilder),
31+
commands.registerCommand("flutter-plus.wrap-repaintboundary", wrapWithRepaintBoundary),
3032

3133
languages.registerCodeActionsProvider(
3234
DART_MODE,

0 commit comments

Comments
 (0)