Skip to content

Commit 251abcb

Browse files
authored
Merge pull request #4 from PlugFox/feature/wrap-with-sizedbox
Wrap with SizedBox
2 parents ea341af + 7382cf2 commit 251abcb

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This package extends your Flutter development experience by providing convenient
88

99
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.
1010

11+
- **Wrap with SizedBox**: Surround your widget with a `SizedBox` to provide constraints on its size, such as width, height, or aspect ratio.
1112
- **Wrap with ListenableBuilder**: Easily wrap any widget with a `ListenableBuilder` to rebuild the widget based on changes in a `Listenable` object.
1213
- **Wrap with ValueListenableBuilder<T>**: Automatically wrap your widget with a `ValueListenableBuilder` to react to changes in a `ValueListenable<T>`.
1314
- **Wrap with RepaintBoundary**: Encapsulate your widget within a `RepaintBoundary` to isolate its repaint process, improving performance in complex UIs.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Flutter Plus",
44
"description": "Extension with various improvements for Flutter",
55
"icon": "assets/logo.png",
6-
"version": "0.4.0",
6+
"version": "0.5.0",
77
"pricing": "Free",
88
"engines": {
99
"vscode": "^1.92.0"
@@ -39,6 +39,10 @@
3939
"command": "flutter-plus.sealed-states",
4040
"title": "Create Sealed States"
4141
},
42+
{
43+
"command": "flutter-plus.wrap-sizedbox",
44+
"title": "Wrap with SizedBox"
45+
},
4246
{
4347
"command": "flutter-plus.wrap-listenablebuilder",
4448
"title": "Wrap with ListenableBuilder"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export class CodeActionWrap implements CodeActionProvider {
1212
if (selectedText === "") return [];
1313

1414
return [
15+
{
16+
command: "flutter-plus.wrap-sizedbox",
17+
title: "Wrap with SizedBox",
18+
},
1519
{
1620
command: "flutter-plus.wrap-listenablebuilder",
1721
title: "Wrap with ListenableBuilder",

src/commands/wrap-with.command.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { wrapWith } from "../utils";
22

3+
const snippetSizedBox = (widget: string) => {
4+
return `SizedBox(
5+
width: \${1:double.infinity},
6+
height: \${2:double.infinity},
7+
child: ${widget},
8+
)`;
9+
};
10+
11+
export const wrapWithSizedBox = async () =>
12+
wrapWith(snippetSizedBox);
13+
314
const snippetListenableBuilder = (widget: string) => {
415
return `ListenableBuilder(
516
listenable: \${1:listenable},
@@ -8,6 +19,8 @@ const snippetListenableBuilder = (widget: string) => {
819
)`;
920
};
1021

22+
export const wrapWithListenableBuilder = async () => wrapWith(snippetListenableBuilder);
23+
1124
const snippetValueListenableBuilder = (widget: string) => {
1225
return `ValueListenableBuilder<\${1:Value}>(
1326
valueListenable: \${2:valueListenable},
@@ -16,14 +29,13 @@ const snippetValueListenableBuilder = (widget: string) => {
1629
)`;
1730
};
1831

32+
33+
export const wrapWithValueListenableBuilder = async () => wrapWith(snippetValueListenableBuilder);
34+
1935
const snippetRepaintBoundary = (widget: string) => {
2036
return `RepaintBoundary(
2137
child: ${widget},
2238
)`;
2339
};
2440

25-
export const wrapWithListenableBuilder = async () => wrapWith(snippetListenableBuilder);
26-
27-
export const wrapWithValueListenableBuilder = async () => wrapWith(snippetValueListenableBuilder);
28-
2941
export const wrapWithRepaintBoundary = async () => wrapWith(snippetRepaintBoundary);

src/extension.ts

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

@@ -26,6 +27,7 @@ export function activate(context: vscode.ExtensionContext) {
2627
vscode.window.showInformationMessage('Hello World from Flutter Plus!');
2728
}), */
2829
commands.registerCommand("flutter-plus.sealed-states", sealedStates),
30+
commands.registerCommand("flutter-plus.wrap-sizedbox", wrapWithSizedBox),
2931
commands.registerCommand("flutter-plus.wrap-listenablebuilder", wrapWithListenableBuilder),
3032
commands.registerCommand("flutter-plus.wrap-valuelistenablebuilder", wrapWithValueListenableBuilder),
3133
commands.registerCommand("flutter-plus.wrap-repaintboundary", wrapWithRepaintBoundary),

0 commit comments

Comments
 (0)