diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 07583dd..f9b9763 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ## How to add widget wrappper -1. Add command to package.json +1. Add command to `package.json` ```json { @@ -17,7 +17,7 @@ } ``` -2. Add snippet to src/commands/wrap-with.command.ts +2. Add snippet to `src/commands/wrap-with.command.ts` ```ts const snippetListenableBuilder = (widget: string) => { @@ -32,7 +32,18 @@ export const wrapWithListenableBuilder = async () => wrapWith(snippetListenableBuilder); ``` -3. Add command to src/extension.ts +3. Add action to `src/code-actions/code-action-wrap.ts` + +```ts + return [ + { + command: "flutter-plus.wrap-listenablebuilder", + title: "Wrap with ListenableBuilder", + } + ] +``` + +4. Add command to `src/extension.ts` ```ts export function activate(context: vscode.ExtensionContext) { diff --git a/README.md b/README.md index d89471d..bc5a954 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,103 @@ # Flutter Plus Extension add some useful commands to Flutter development in Visual Studio Code. + +## Wrap with... + +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. + +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. + +- **Wrap with ListenableBuilder**: Easily wrap any widget with a `ListenableBuilder` to rebuild the widget based on changes in a `Listenable` object. +- **Wrap with ValueListenableBuilder**: Automatically wrap your widget with a `ValueListenableBuilder` to react to changes in a `ValueListenable`. +- **Wrap with RepaintBoundary**: Encapsulate your widget within a `RepaintBoundary` to isolate its repaint process, improving performance in complex UIs. + + +## Markdown snippets + +| Shortcut | Description | +| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| unreleased | Create a new unreleased section. Used to list features that are not yet released. | +| version | Create a new version section. Used to list features that are released in a specific version. | + + +## Dart snippets + +| Shortcut | Description | +| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| main | Generates a main function with error handling and zone management for Dart applications. | +| try | Creates a try-catch-finally block, useful for managing exceptions and ensuring cleanup code runs. | +| timeout | Creates a timeout handler for setting execution limits on asynchronous operations. | +| stopwatch | Initializes a Stopwatch to measure and log elapsed time for code execution. | +| conditional | Generates platform-specific imports based on the environment (VM or JS), ensuring compatibility across different platforms. | +| dvd | Inserts a divider comment line, useful for visually separating sections of code. | +| reverseList | Generates a loop for traversing a list in reverse order. | +| part | Adds a part directive to include the specified Dart file as part of the current library. | +| mocks | Imports a Dart file containing mock implementations for testing purposes. | +| toStr | Overrides the `toString` method for a custom object, providing a string representation of the object for debugging or logging. | +| equals | Generates hash code and equals methods, overriding the `==` operator and the `hashCode` getter for custom object comparison. | +| nosm | Implements the `noSuchMethod` method, handling calls to non-existent methods or properties. | +| test | Creates a test function, setting up a basic test case using the `test` package. | +| pragma | Inserts a pragma directive to optimize or modify Dart VM/compiler behavior based on the specified options. | +| doc-disabled | Adds a comment annotation to disable documentation generation for the specified block of code. | +| doc-category | Categorizes a block of documentation with the specified category or subcategory tags. | +| doc-image | Embeds an image within a block of documentation, using the specified URL as the source. | +| doc-animation | Embeds an animation within a block of documentation, with options for specifying the size and source URL. | +| doc-html | Injects custom HTML into a documentation comment, allowing for rich formatting or content inclusion. | +| newtmpl | Creates a new Dart documentation template with the current file's name as the prefix, useful for reusing content across multiple documentation blocks. | +| usetmpl | Inserts an existing Dart documentation macro, using the current file's name as the prefix, to maintain consistency in documentation. | +| deprecated | Marks a class, method, or property as deprecated, indicating that it should no longer be used and may be removed in future versions. | +| meta | Applies a meta annotation to a class, method, or property, providing additional metadata for tooling or code analysis purposes. | +| coverage | Adds a coverage annotation to mark lines or blocks of code that should be ignored by test coverage tools. | + + +## Flutter snippets + +| Shortcut | Description | +| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| mateapp | Creates a new `MaterialApp` widget, an application that uses Material Design components and theming. | +| cupeapp | Creates a new `CupertinoApp` widget, an application that uses Cupertino (iOS-style) design components and theming. | +| scaffold | Creates a new `Scaffold` widget, implementing the basic Material Design visual layout structure including app bar, drawer, and floating action button. | +| stl | Generates a new `StatelessWidget` class, a widget that does not require mutable state and is rebuilt only when the configuration changes. | +| stlChild | Generates a new `StatelessWidget` class with a child widget, for cases where a single child widget needs to be passed and rendered. | +| stf | Generates a new `StatefulWidget` class, a widget that has mutable state that can change over time, and its associated `State` class. | +| stfChild | Generates a new `StatefulWidget` class with a child widget, allowing for a stateful widget to have a single child widget passed in and managed. | +| inh | Creates a new `InheritedWidget` class, which efficiently propagates information down the widget tree to descendants. | +| of | Generates a static `of` method for an `InheritedWidget`, returning the nearest widget of the specified type and creating a dependency on it. | +| stateOf | Generates a static `stateOf` method for a `State` object, returning the `State` object of the nearest ancestor `StatefulWidget` of the specified type. | +| widgetOf | Generates a static `widgetOf` method for a `Widget` object, returning the nearest ancestor widget of the specified type. | +| painter | Creates a new `CustomPainter` class, which provides a canvas on which to draw during the paint phase, used for drawing custom shapes and graphics. | +| clipper | Creates a new `CustomClipper` class, used for defining custom clipping shapes for widgets. | +| debugFillProperties | Generates a `debugFillProperties` method to add additional properties associated with the widget for debugging purposes. | +| initS | Creates an `initState` method, called when this object is inserted into the widget tree for the first time, typically used to initialize state. | +| dispose | Creates a `dispose` method, called when this object is permanently removed from the widget tree, used for cleanup of resources. | +| reassemble | Creates a `reassemble` method, called during debugging whenever the application is reassembled, for example, during a hot reload. | +| didChangeD | Creates a `didChangeDependencies` method, called when a dependency of the `State` object changes. | +| didUpdateW | Creates a `didUpdateWidget` method, called whenever the widget’s configuration changes. | +| build | Generates a `build` method, describing the part of the user interface represented by this widget. | +| listViewBuilder | Creates a `ListView.builder`, a scrollable list that lazily builds its children as they scroll into view, useful for large or infinite lists. | +| listViewSeparated | Creates a `ListView.separated`, a scrollable list that displays a separator widget between each child widget, ideal for lists with visually distinct sections. | +| gridViewBuilder | Creates a `GridView.builder`, a scrollable grid of widgets that are created on demand. | +| gridViewCount | Creates a `GridView.count`, a scrollable grid of widgets with a fixed number of tiles in the cross axis. | +| gridViewE | Creates a `GridView.extent`, a scrollable grid of widgets with tiles that each have a maximum cross-axis extent. | +| customScrollV | Creates a `CustomScrollView`, a scrollable area that creates custom scroll effects using slivers. | +| builder | Creates a `Builder` widget, which allows you to create a child widget in a way that depends on the `BuildContext`. | +| wrapWithBuilder | Wraps the selected widget with a `Builder` widget, delegating the widget building process to a callback. | +| stfBuilder | Creates a `StatefulBuilder` widget, which allows for state management and rebuilding a specific portion of the widget tree. | +| strBuilder | Creates a `StreamBuilder` widget, which rebuilds itself based on the latest snapshot of interaction with a `Stream`. | +| lisBuilder | Creates a `ListenableBuilder` widget, which rebuilds itself based on the latest value of a `Listenable` it listens to. | +| valLisBuilder | Creates a `ValueListenableBuilder` widget, which rebuilds itself based on the latest value of a `ValueListenable`. | +| animBuilder | Creates an `AnimatedBuilder` widget, which rebuilds itself based on an animation. | +| switcher | Creates an `AnimatedSwitcher` widget, which switches between two children and animates the transition between them. | +| orientBuilder | Creates an `OrientationBuilder` widget, which rebuilds itself based on the latest orientation of the device (portrait or landscape). | +| layBuilder | Creates a `LayoutBuilder` widget, which rebuilds itself based on the latest layout constraints, useful for responsive layouts. | +| repBound | Creates a `RepaintBoundary` widget, which isolates repaints so that a repaint of one child is separate from others, improving performance. | +| singleChildSV | Creates a `SingleChildScrollView` widget, which allows a single child to be scrolled. | +| futBuilder | Creates a `FutureBuilder` widget, which rebuilds itself based on the latest snapshot of interaction with a `Future`. | +| tweenAnimBuilder | Creates a `TweenAnimationBuilder` widget, which animates a property of a widget to a target value whenever the target value changes. | +| testWidget | Creates a `testWidgets` function for testing a widget, typically used in Flutter's unit testing framework. | +| row | Creates a `Row` widget, which displays its children in a horizontal array. | +| col | Creates a `Column` widget, which displays its children in a vertical array. | +| wrap | Creates a `Wrap` widget, which displays its children in multiple horizontal or vertical runs, wrapping to the next line when necessary. | +| stack | Creates a `Stack` widget, which allows you to place widgets on top of each other in a z-order. | +| fittedbox | Creates a `FittedBox` widget, which scales and positions its child within itself according to the specified fit. | diff --git a/package.json b/package.json index faf8b39..5e17d28 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Flutter Plus", "description": "Extension with various improvements for Flutter", "icon": "assets/logo.png", - "version": "0.3.0", + "version": "0.4.0", "pricing": "Free", "engines": { "vscode": "^1.92.0" @@ -46,6 +46,10 @@ { "command": "flutter-plus.wrap-valuelistenablebuilder", "title": "Wrap with ValueListenableBuilder" + }, + { + "command": "flutter-plus.wrap-repaintboundary", + "title": "Wrap with RepaintBoundary" } ], "submenus": [ @@ -72,6 +76,10 @@ "commandPalette": [] }, "snippets": [ + { + "language": "markdown", + "path": "./snippets/markdown.json" + }, { "language": "dart", "path": "./snippets/dart.json" diff --git a/snippets/dart.json b/snippets/dart.json index 3c8582e..cbadb29 100644 --- a/snippets/dart.json +++ b/snippets/dart.json @@ -2,7 +2,7 @@ "Main entry point": { "scope": "flutter, dart", "prefix": "main", - "description": "Main entry point", + "description": "Generates a main function with error handling and zone management for Dart applications.", "body": [ "import 'dart:async';\n", "@pragma('vm:entry-point')", @@ -17,7 +17,7 @@ "Try-catch-finally block": { "scope": "flutter, dart", "prefix": "try", - "description": "Try-catch-finally block", + "description": "Creates a try-catch-finally block, useful for managing exceptions and ensuring cleanup code runs.", "body": [ "try {", " // ...", @@ -31,13 +31,13 @@ "Timeout handler": { "scope": "flutter, dart", "prefix": "timeout", - "description": "Timeout handler", + "description": "Creates a timeout handler for setting execution limits on asynchronous operations.", "body": "timeout(const Duration(milliseconds: 5000))${0:;}" }, "Stopwatch": { "scope": "flutter, dart", "prefix": "stopwatch", - "description": "Stopwatch", + "description": "Initializes a Stopwatch to measure and log elapsed time for code execution.", "body": [ "final stopwatch = Stopwatch()..start();", "try {", @@ -54,10 +54,11 @@ "Platform conditional imports": { "scope": "flutter, dart", "prefix": [ + "conditional", "conditional_imports", "import_conditional" ], - "description": "Platform conditional imports", + "description": "Generates platform-specific imports based on the environment (VM or JS), ensuring compatibility across different platforms.", "body": [ "import 'stub.dart'", " // ignore: uri_does_not_exist", @@ -66,55 +67,13 @@ " if (dart.library.io) 'io.dart';\n" ] }, - "Changelog unreleased": { - "scope": "md, markdown", - "prefix": [ - "changelog_unreleased", - "unreleased" - ], - "description": "Changelog unreleased", - "body": [ - "## Unreleased", - "", - "- **ADDED**: ${0}", - "- **CHANGED**: ", - "- **DEPRECATED**: ", - "- **REMOVED**: ", - "- **FIXED**: ", - "- **SECURITY**: ", - "- **REFACTOR**: ", - "- **DOCS**: ", - " " - ] - }, - "Changelog version": { - "scope": "md, markdown", - "prefix": [ - "changelog_version", - "version" - ], - "description": "Changelog version section", - "body": [ - "## ${1:0}.${2:0}.${3:0}", - "", - "- **ADDED**: ${0}", - "- **CHANGED**: ", - "- **DEPRECATED**: ", - "- **REMOVED**: ", - "- **FIXED**: ", - "- **SECURITY**: ", - "- **REFACTOR**: ", - "- **DOCS**: ", - " " - ] - }, "Divider": { "scope": "flutter, dart", "prefix": [ "dvd", "divider_comment" ], - "description": "Divider comment line", + "description": "Inserts a divider comment line, useful for visually separating sections of code.", "body": "// --- ${1} --- //\n\n$0" }, "Reverse bypass": { @@ -122,7 +81,7 @@ "prefix": [ "reverseList" ], - "description": "Reverse list traversal in a loop", + "description": "Generates a loop for traversing a list in reverse order.", "body": [ "for (var i = list.length - 1; i >= 0; i--) $0" ] @@ -130,7 +89,7 @@ "Part": { "scope": "flutter, dart", "prefix": "part", - "description": "Part of file", + "description": "Adds a part directive to include the specified Dart file as part of the current library.", "body": [ "part '${TM_FILENAME_BASE}.g.dart';$0" ] @@ -138,11 +97,20 @@ "Mocks": { "scope": "flutter, dart", "prefix": "mocks", - "description": "Import mocks file", + "description": "Imports a Dart file containing mock implementations for testing purposes.", "body": [ "import '${TM_FILENAME_BASE}.mocks.dart';$0" ] }, + "toString": { + "scope": "flutter, dart", + "prefix": "toStr", + "description": "Overrides the `toString` method for a custom object, providing a string representation of the object for debugging or logging.", + "body": [ + "@override", + "String toString() => '${0}'" + ] + }, "Hash Code": { "scope": "flutter, dart", "prefix": [ @@ -150,7 +118,7 @@ "equals", "==" ], - "description": "Hash Code and Equals override", + "description": "Generates hash code and equals methods, overriding the `==` operator and the `hashCode` getter for custom object comparison.", "body": [ "@override", "int get hashCode => id.hashCode;\n", @@ -167,7 +135,7 @@ "nosm", "noSuchMethod" ], - "description": "This method is invoked when a non-existent method or property is accessed.", + "description": "Implements the `noSuchMethod` method, handling calls to non-existent methods or properties.", "body": [ "@override", "dynamic noSuchMethod(Invocation invocation) {", @@ -181,7 +149,7 @@ "test", "unitTest" ], - "description": "Create a test function", + "description": "Creates a test function, setting up a basic test case using the `test` package.", "body": [ "test('${1:test description}', () {", " ${0:expect(true, isTrue);}", @@ -191,10 +159,10 @@ "Pragma": { "scope": "flutter, dart", "prefix": [ - "@pragma", - "pragma" + "pragma", + "@pragma" ], - "description": "Pragma annotation https://mrale.ph/dartvm/pragmas.html", + "description": "Inserts a pragma directive to optimize or modify Dart VM/compiler behavior based on the specified options.", "body": "@pragma(${1|'vm:entry-point','vm:never-inline','vm:prefer-inline','dart2js:tryInline','vm:notify-debugger-on-exception','vm:invisible','vm:always-consider-inlining','flutter:keep-to-string','flutter:keep-to-string-in-subtypes'|})" }, "Dart doc disable documentation": { @@ -203,18 +171,16 @@ "doc-disabled", "@doc-disabled" ], - "description": "No documentation annotation", + "description": "Adds a comment annotation to disable documentation generation for the specified block of code.", "body": [] }, "Dart doc category": { "scope": "flutter, dart", "prefix": [ - "category", "doc-category", - "dartdoc-category", "@doc-category" ], - "description": "Add category to documentation", + "description": "Categorizes a block of documentation with the specified category or subcategory tags.", "body": [ "/// {@${1|category,subCategory|} ${0}}" ] @@ -223,10 +189,9 @@ "scope": "flutter, dart", "prefix": [ "doc-image", - "dartdoc-image", "@doc-image" ], - "description": "Add image to documentation", + "description": "Embeds an image within a block of documentation, using the specified URL as the source.", "body": [ "/// {@image }" ] @@ -235,23 +200,22 @@ "scope": "flutter, dart", "prefix": [ "doc-animation", - "dartdoc-animation", "@doc-animation" ], - "description": "Add animation to documentation", + "description": "Embeds an animation within a block of documentation, with options for specifying the size and source URL.", "body": "/// {@animation name 100 200 ${0:https://host.tld/path/to/video.mp4}}" }, "Dart doc new template": { "scope": "flutter, dart", "prefix": [ + "newtmpl", "@template", "template", - "dartdoc-new-template", + "doc-new-template", "doc-new-macro", - "newtmpl", "@doc-template" ], - "description": "Creates a new dartdoc template with current file's name as its prefix", + "description": "Creates a new Dart documentation template with the current file's name as the prefix, useful for reusing content across multiple documentation blocks.", "body": [ "/// {@template ${1:$TM_FILENAME_BASE}}", "/// ${0:Body of the template}", @@ -261,27 +225,25 @@ "Dart doc use macro": { "scope": "flutter, dart", "prefix": [ + "usetmpl", "@macro", "macro", - "dartdoc-use-template", + "doc-use-template", "doc-use-macro", - "usetmpl", "@doc-macro" ], - "description": "Uses existing dartdoc macro with current file's name as its prefix", + "description": "Inserts an existing Dart documentation macro, using the current file's name as the prefix, to maintain consistency in documentation.", "body": "/// {@macro ${0:$TM_FILENAME_BASE}}" }, "Dart doc inject html": { "scope": "flutter, dart", "prefix": [ + "doc-html", "@inject-html", "inject-html", - "dartdoc-html", - "doc-html", - "html", "@doc-html" ], - "description": "Injects html into the current comment", + "description": "Injects custom HTML into a documentation comment, allowing for rich formatting or content inclusion.", "body": [ "/// {@inject-html}", "/// ${0:

[The HTML to inject.]()

}", @@ -291,21 +253,21 @@ "Deprecated": { "scope": "flutter, dart", "prefix": [ - "@deprecated", - "deprecated" + "deprecated", + "@deprecated" ], - "description": "Deprecated", + "description": "Marks a class, method, or property as deprecated, indicating that it should no longer be used and may be removed in future versions.", "body": "@Deprecated('${0:Reason}')" }, "Meta": { "scope": "flutter, dart", "prefix": [ - "@meta", "meta", + "@meta", "@annotation", "annotation" ], - "description": "Meta annotation", + "description": "Applies a meta annotation to a class, method, or property, providing additional metadata for tooling or code analysis purposes.", "body": "@${1|immutable,useResult,internal,protected,literal,mustCallSuper,sealed,alwaysThrows,factory,visibleForOverriding,visibleForTesting,experimental,nonVirtual,doNotStore,optionalTypeArgs|}" }, "Coverage": { @@ -313,7 +275,7 @@ "prefix": [ "coverage" ], - "description": "Coverage annotation", + "description": "Adds a coverage annotation to mark lines or blocks of code that should be ignored by test coverage tools.", "body": "// coverage:${1|ignore-line,ignore-start,ignore-end,ignore-file|}" } } \ No newline at end of file diff --git a/snippets/flutter.json b/snippets/flutter.json index 660564b..23c750d 100644 --- a/snippets/flutter.json +++ b/snippets/flutter.json @@ -2,7 +2,7 @@ "Material App": { "scope": "flutter, dart", "prefix": "mateapp", - "description": "Create a MaterialApp", + "description": "Creates a MaterialApp widget, a base application structure using Material Design components.", "body": [ "import 'dart:async';\n", "import 'package:flutter/material.dart';\n", @@ -36,7 +36,7 @@ "Cupertino App": { "scope": "flutter, dart", "prefix": "cupeapp", - "description": "Create a CupertinoApp", + "description": "Creates a CupertinoApp widget, a base application structure using Cupertino (iOS-style) design components.", "body": [ "import 'dart:async';\n", "import 'package:flutter/cupertino.dart';\n\n", @@ -70,7 +70,7 @@ "Scaffold": { "scope": "flutter, dart", "prefix": "scaffold", - "description": "Create a Scaffold", + "description": "Creates a Scaffold widget, the basic structure for Material Design visual layout.", "body": [ "Scaffold(", " appBar: AppBar(", @@ -90,7 +90,7 @@ "stl", "statelessWidget" ], - "description": "Snippet for Stateless Widget", + "description": "Generates a new StatelessWidget class.", "body": [ "import 'package:flutter/widgets.dart';\n\n", "/// {@template ${2:$TM_FILENAME_BASE}}", @@ -114,7 +114,7 @@ "stlChild", "statelessWidgetWithChild" ], - "description": "Snippet for Stateless Widget with child", + "description": "Generates a new StatelessWidget class with a child widget.", "body": [ "import 'package:flutter/widgets.dart';\n\n", "/// {@template ${2:$TM_FILENAME_BASE}}", @@ -142,7 +142,7 @@ "stf", "statefulWidget" ], - "description": "Snippet for Stateful Widget", + "description": "Generates a new StatefulWidget class.", "body": [ "import 'package:flutter/widgets.dart';", "import 'package:meta/meta.dart';\n\n", @@ -207,7 +207,7 @@ "stfChild", "statefulfWithChild" ], - "description": "Snippet for Stateful Widget with child", + "description": "Generates a new StatefulWidget class with a child widget.", "body": [ "import 'package:flutter/widgets.dart';", "import 'package:meta/meta.dart';\n\n", @@ -279,7 +279,7 @@ "inh", "inheritedWidget" ], - "description": "Inherited Widget", + "description": "Generates an InheritedWidget class.", "body": [ "import 'package:flutter/widgets.dart';\n\n", "/// {@template ${2:$TM_FILENAME_BASE}}", @@ -304,7 +304,7 @@ "of", "maybeOf" ], - "description": "InheritedWidget.of(BuildContext)", + "description": "Creates a static `of` method for an InheritedWidget.", "body": [ "/// The state from the closest instance of this class", "/// that encloses the given context, if any.", @@ -330,7 +330,7 @@ "stateOf": { "scope": "flutter, dart", "prefix": "stateOf", - "description": "StatefulWidget.of(BuildContext)", + "description": "Creates a static `stateOf` method for a State object.", "body": [ "/// The state from the closest instance of this class", "/// that encloses the given context, if any.", @@ -354,7 +354,7 @@ "widgetOf": { "scope": "flutter, dart", "prefix": "widgetOf", - "description": "StatelessWidget.of(BuildContext)", + "description": "Creates a static `widgetOf` method for a Widget object.", "body": [ "/// The state from the closest instance of this class", "/// that encloses the given context, if any.", @@ -378,7 +378,7 @@ "Build Method": { "scope": "flutter, dart", "prefix": "build", - "description": "Describes the part of the user interface represented by this widget.", + "description": "Creates a `build` method, describing the part of the UI represented by this widget.", "body": [ "@override", "Widget build(BuildContext context) =>", @@ -391,7 +391,7 @@ "painter", "customPainter" ], - "description": "Used for creating custom paint", + "description": "Creates a CustomPainter class for custom drawing.", "body": [ "/// {@template ${2:$TM_FILENAME_BASE}}", "/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}}Painter.", @@ -419,10 +419,10 @@ "clipper", "customClipper" ], - "description": "Used for creating custom shapes", + "description": "Creates a CustomClipper class for defining custom clipping shapes.", "body": [ "/// {@template ${2:$TM_FILENAME_BASE}}", - "/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}}Painter.", + "/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}}Clipper.", "/// {@endtemplate}", "class ${1}Clipper extends CustomClipper {", " /// {@macro ${2}}", @@ -441,7 +441,7 @@ "debugFillProperties": { "scope": "flutter, dart", "prefix": "debugFillProperties", - "description": "debugFillProperties", + "description": "Creates a `debugFillProperties` method for adding debug properties.", "body": [ "@override", "void debugFillProperties(DiagnosticPropertiesBuilder properties) =>", @@ -460,7 +460,7 @@ "initState": { "scope": "flutter, dart", "prefix": "initS", - "description": "Called when this object is inserted into the tree. The framework will call this method exactly once for each State object it creates.", + "description": "Creates an `initState` method, initializing state when the widget is inserted into the tree.", "body": [ "@override", "void initState() {", @@ -472,19 +472,19 @@ "dispose": { "scope": "flutter, dart", "prefix": "dispose", + "description": "Creates a `dispose` method, cleaning up resources when the widget is removed from the tree.", "body": [ "@override", "void dispose() {", " ${0:}", " super.dispose();", "}" - ], - "description": "Called when this object is removed from the tree permanently. The framework calls this method when this State object will never build again." + ] }, "reassemble": { "scope": "flutter, dart", "prefix": "reassemble", - "description": "Called whenever the application is reassembled during debugging, for example during hot reload.", + "description": "Creates a `reassemble` method, called during hot reload.", "body": [ "@override", "void reassemble(){", @@ -496,7 +496,7 @@ "didChangeDependencies": { "scope": "flutter, dart", "prefix": "didChangeD", - "description": "Called when a dependency of this State object changes", + "description": "Creates a `didChangeDependencies` method, called when a dependency of this `State` object changes.", "body": [ "@override", "void didChangeDependencies() {", @@ -508,7 +508,7 @@ "didUpdateWidget": { "scope": "flutter, dart", "prefix": "didUpdateW", - "description": "Called whenever the widget configuration changes.", + "description": "Creates a `didUpdateWidget` method, called when the widget’s configuration changes.", "body": [ "@override", "void didUpdateWidget (covariant ${1:Type} ${2:oldWidget}) {", @@ -520,7 +520,7 @@ "ListView.builder": { "scope": "flutter, dart", "prefix": "listViewBuilder", - "description": "Creates a scrollable, linear array of widgets that are created on demand.Providing a non-null `itemCount` improves the ability of the [ListView] to estimate the maximum scroll extent.", + "description": "Creates a `ListView.builder`, a scrollable list that lazily builds its children as they scroll into view.", "body": [ "ListView.builder(", " itemCount: ${1:1},", @@ -532,7 +532,7 @@ "ListView.separated": { "scope": "flutter, dart", "prefix": "listViewSeparated", - "description": "Creates a fixed-length scrollable linear array of list 'items' separated by list item 'separators'.", + "description": "Creates a `ListView.separated`, a scrollable list with separators between items.", "body": [ "ListView.separated(", " itemCount: ${1:1},", @@ -548,7 +548,7 @@ "GridView.builder": { "scope": "flutter, dart", "prefix": "gridViewBuilder", - "description": "Creates a scrollable, 2D array of widgets that are created on demand. Providing a non-null `itemCount` improves the ability of the [GridView] to estimate the maximum scroll extent.", + "description": "Creates a `GridView.builder`, a scrollable grid of widgets that are created on demand.", "body": [ "GridView.builder(", " gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(", @@ -564,7 +564,7 @@ "GridView.count": { "scope": "flutter, dart", "prefix": "gridViewCount", - "description": "Creates a scrollable, 2D array of widgets with a fixed number of tiles in the cross axis.", + "description": "Creates a `GridView.count`, a scrollable grid of widgets with a fixed number of tiles in the cross axis.", "body": [ "GridView.count(", " crossAxisSpacing: ${1:1},", @@ -579,7 +579,7 @@ "GridView.extent": { "scope": "flutter, dart", "prefix": "gridViewE", - "description": "Creates a scrollable, 2D array of widgets with tiles that each have a maximum cross-axis extent.", + "description": "Creates a `GridView.extent`, a scrollable grid of widgets with tiles that each have a maximum cross-axis extent.", "body": [ "GridView.extent(", " maxCrossAxisExtent: ${1:2},", @@ -592,7 +592,7 @@ "Custom Scroll View": { "scope": "flutter, dart", "prefix": "customScrollV", - "description": "Creates a `ScrollView` that creates custom scroll effects using slivers. If the `primary` argument is true, the `controller` must be null.", + "description": "Creates a `CustomScrollView`, a scrollable area that creates custom scroll effects using slivers.", "body": [ "CustomScrollView(", " slivers: [", @@ -604,7 +604,7 @@ "Builder": { "scope": "flutter, dart", "prefix": "builder", - "description": "Creates a widget that delegates its build to a callback.", + "description": "Creates a `Builder` widget, delegating the widget building process to a callback.", "body": [ "Builder(", " builder: (context) =>", @@ -617,7 +617,7 @@ "prefix": [ "wrapWithBuilder" ], - "description": "Wrap a widget with Builder widget.", + "description": "Wraps a widget with a `Builder` widget.", "body": [ "Builder(", " builder: (context) =>", @@ -627,8 +627,11 @@ }, "Stateful Builder": { "scope": "flutter, dart", - "prefix": "statefulBuilder", - "description": "Creates a widget that both has state and delegates its build to a callback. Useful for rebuilding specific sections of the widget tree.", + "prefix": [ + "stfBuilder", + "statefulBuilder" + ], + "description": "Creates a `StatefulBuilder` widget, allowing for state management and rebuilding a specific portion of the widget tree.", "body": [ "StatefulBuilder(", " builder: (context, setState) =>", @@ -638,8 +641,11 @@ }, "Stream Builder": { "scope": "flutter, dart", - "prefix": "streamBuilder", - "description": "Creates a new `StreamBuilder` that builds itself based on the latest snapshot of interaction with the specified `stream`", + "prefix": [ + "strBuilder", + "streamBuilder" + ], + "description": "Creates a `StreamBuilder` widget, rebuilding itself based on the latest snapshot of interaction with a `Stream`.", "body": [ "StreamBuilder<${1:int}>(", " initialData: ${2:initialData},", @@ -649,39 +655,61 @@ ")," ] }, - "Value Listenable Builder": { + "Animated Builder": { "scope": "flutter, dart", - "prefix": "valueListenableBuilder", - "description": "Given a ValueListenable and a builder which builds widgets from concrete values of T, this class will automatically register itself as a listener of the ValueListenable and call the builder with updated values when the value changes.", + "prefix": [ + "animBuilder", + "animatedBuilder" + ], + "description": "Creates an `AnimatedBuilder` widget, rebuilding itself based on an animation.", "body": [ - "ValueListenableBuilder<${1:int}>(", - " valueListenable: ${2: null},", - " builder: (context, value, child) =>", + "AnimatedBuilder(", + " animation: ${1:animation},", + " builder: (context, child) =>", " ${0:const Placeholder()},", " child: ${2:child},", ")," ] }, - "Animated Builder": { + "Listenable Builder": { "scope": "flutter, dart", - "prefix": "animatedBldr", - "description": "Creates an Animated Builder. The widget specified to `child` is passed to the `builder`", + "prefix": [ + "lisBuilder", + "listenableBuilder" + ], + "description": "Creates a `ListenableBuilder` widget, rebuilding itself based on the latest value of a `Listenable` it listens to.", "body": [ - "AnimatedBuilder(", - " animation: ${1:animation},", + "ListenableBuilder(", + " listenable: ${1: null},", " builder: (context, child) =>", " ${0:const Placeholder()},", " child: ${2:child},", ")," ] }, + "Value Listenable Builder": { + "scope": "flutter, dart", + "prefix": [ + "valLisBuilder", + "valueListenableBuilder" + ], + "description": "Creates a `ValueListenableBuilder` widget, rebuilding itself based on the latest value of a `ValueListenable`.", + "body": [ + "ValueListenableBuilder<${1:int}>(", + " valueListenable: ${2: null},", + " builder: (context, value, child) =>", + " ${0:const Placeholder()},", + " child: ${2:child},", + ")," + ] + }, "Animated Switcher": { "scope": "flutter, dart", "prefix": [ - "animatedSwitcher", - "switcher" + "switcher", + "animatedSwitcher" ], - "description": "Creates an Animated Switcher.", + "description": "Creates an `AnimatedSwitcher` widget, switching between two children and animating the transition.", "body": [ "AnimatedSwitcher(", " duration: const Duration(milliseconds: 350),", @@ -691,8 +719,11 @@ }, "Orientation Builder": { "scope": "flutter, dart", - "prefix": "orientationBuilder", - "description": "Creates a builder which allows for the orientation of the device to be specified and referenced", + "prefix": [ + "orientBuilder", + "orientationBuilder" + ], + "description": "Creates an `OrientationBuilder` widget, rebuilding itself based on the latest orientation of the device (portrait or landscape).", "body": [ "OrientationBuilder(", " builder: (context, orientation) {", @@ -703,8 +734,11 @@ }, "Layout Builder": { "scope": "flutter, dart", - "prefix": "layoutBuilder", - "description": "Similar to the Builder widget except that the framework calls the builder function at layout time and provides the parent widget's constraints.", + "prefix": [ + "layBuilder", + "layoutBuilder" + ], + "description": "Creates a `LayoutBuilder` widget, rebuilding itself based on the latest layout constraints, useful for responsive layouts.", "body": [ "LayoutBuilder(", " builder: (context, constraints) {", @@ -715,8 +749,11 @@ }, "Repaint boundary": { "scope": "flutter, dart", - "prefix": "repaintBoundary", - "description": "Creates a widget that isolates repaints.", + "prefix": [ + "repBound", + "repaintBoundary" + ], + "description": "Creates a `RepaintBoundary` widget, isolating repaints to improve performance.", "body": [ "RepaintBoundary(", " key: ValueKey(${1:name}),", @@ -727,6 +764,7 @@ "Single Child ScrollView": { "scope": "flutter, dart", "prefix": "singleChildSV", + "description": "Creates a `SingleChildScrollView` widget, allowing a single child to be scrolled.", "body": [ "SingleChildScrollView(", " controller: ${1:controller,}", @@ -734,12 +772,15 @@ " ${0:}", " ),", ")," - ], - "description": "Creates a scroll view with a single child" + ] }, "Future Builder": { "scope": "flutter, dart", - "prefix": "futureBldr", + "prefix": [ + "futBuilder", + "futureBuilder" + ], + "description": "Creates a `FutureBuilder` widget, rebuilding itself based on the latest snapshot of interaction with a `Future`.", "body": [ "FutureBuilder(", " future: ${1:Future},", @@ -748,13 +789,15 @@ " return ${3:};", " },", ")," - ], - "description": "Creates a Future Builder. This builds itself based on the latest snapshot of interaction with a Future." + ] }, "Tween Animation Builder": { "scope": "flutter, dart", - "prefix": "tweenAnimationBuilder", - "description": "Widget builder that animates a property of a Widget to a target value whenever the target value changes.", + "prefix": [ + "tweenAnimBuilder", + "tweenAnimationBuilder" + ], + "description": "Creates a `TweenAnimationBuilder` widget, animating a property of a widget to a target value whenever the target value changes.", "body": [ "TweenAnimationBuilder<${3:Object?}>(", " duration: ${1:const Duration(),}", @@ -770,7 +813,7 @@ "testWidget", "widgetTest" ], - "description": "Create a testWidgets function", + "description": "Creates a `testWidgets` function for testing a widget.", "body": [ "testWidgets(", " \"${1:test description}\",", @@ -779,5 +822,83 @@ " },", ");" ] + }, + "Row": { + "scope": "flutter, dart", + "prefix": "row", + "description": "Creates a `Row` widget, which displays its children in a horizontal array.", + "body": [ + "Row(", + " mainAxisSize: MainAxisSize.${1|min,max|},", + " mainAxisAlignment: MainAxisAlignment.${2|start,end,center,spaceBetween,spaceAround,spaceEvenly|},", + " crossAxisAlignment: CrossAxisAlignment.${3|start,end,center,stretch,baseline|},", + " children: [", + " // SizedBox, Expanded, Flexible, Spacer, VerticalDivider", + " ${0:Placeholder()},", + " ],", + ")," + ] + }, + "Column": { + "scope": "flutter, dart", + "prefix": [ + "col", + "column" + ], + "description": "Creates a `Column` widget, which displays its children in a vertical array.", + "body": [ + "Column(", + " mainAxisSize: MainAxisSize.${1|min,max|},", + " mainAxisAlignment: MainAxisAlignment.${2|start,end,center,spaceBetween,spaceAround,spaceEvenly|},", + " crossAxisAlignment: CrossAxisAlignment.${3|start,end,center,stretch,baseline|},", + " children: [", + " // SizedBox, Expanded, Flexible, Spacer, Divider", + " ${0:Placeholder()},", + " ],", + ")," + ] + }, + "Wrap": { + "scope": "flutter, dart", + "prefix": "wrap", + "description": "Creates a `Wrap` widget, which displays its children in multiple horizontal or vertical runs.", + "body": [ + "Wrap(", + " direction: Axis.${1|horizontal,vertical|},", + " spacing: ${2:8.0},", + " runSpacing: ${3:4.0},", + " alignment: WrapAlignment.${4|start,end,center,spaceBetween,spaceAround,spaceEvenly|},", + " crossAxisAlignment: WrapCrossAlignment.${5|start,end,center|},", + " verticalDirection: VerticalDirection.${6|down,up|},", + " children: [", + " ${0:Placeholder()},", + " ],", + ")," + ] + }, + "Stack": { + "scope": "flutter, dart", + "prefix": "stack", + "description": "Creates a `Stack` widget, which allows you to place widgets on top of each other in a z-order.", + "body": [ + "Stack(", + " alignment: Alignment.${1|topLeft,topCenter,center|},", + " children: [", + " ${0:Placeholder()},", + " ],", + ")," + ] + }, + "FittedBox": { + "scope": "flutter, dart", + "prefix": "fittedbox", + "description": "Creates a `FittedBox` widget, which scales and positions its child within itself according to the specified fit.", + "body": [ + "FittedBox(", + " fit: BoxFit.${1|scaleDown,fill,contain,cover,fitWidth,fitHeight,none|},", + " alignment: Alignment.${2:center},", + " child: ${0:Placeholder()},", + ")," + ] } } \ No newline at end of file diff --git a/snippets/markdown.json b/snippets/markdown.json new file mode 100644 index 0000000..5e45357 --- /dev/null +++ b/snippets/markdown.json @@ -0,0 +1,44 @@ +{ + "Changelog unreleased": { + "scope": "md, markdown", + "prefix": [ + "unreleased", + "changelog_unreleased" + ], + "description": "Changelog unreleased", + "body": [ + "## Unreleased", + "", + "- **ADDED**: ${0}", + "- **CHANGED**: ", + "- **DEPRECATED**: ", + "- **REMOVED**: ", + "- **FIXED**: ", + "- **SECURITY**: ", + "- **REFACTOR**: ", + "- **DOCS**: ", + " " + ] + }, + "Changelog version": { + "scope": "md, markdown", + "prefix": [ + "version", + "changelog_version" + ], + "description": "Changelog version section", + "body": [ + "## ${1:0}.${2:0}.${3:0}", + "", + "- **ADDED**: ${0}", + "- **CHANGED**: ", + "- **DEPRECATED**: ", + "- **REMOVED**: ", + "- **FIXED**: ", + "- **SECURITY**: ", + "- **REFACTOR**: ", + "- **DOCS**: ", + " " + ] + } +} \ No newline at end of file diff --git a/src/code-actions/code-action-wrap.ts b/src/code-actions/code-action-wrap.ts index effa2ae..6dca3be 100644 --- a/src/code-actions/code-action-wrap.ts +++ b/src/code-actions/code-action-wrap.ts @@ -4,7 +4,6 @@ import { CodeAction, CodeActionKind, CodeActionProvider, window } from "vscode"; import { getSelectedText } from "../utils"; export class CodeActionWrap implements CodeActionProvider { - public provideCodeActions(): CodeAction[] { const editor = window.activeTextEditor; if (!editor) return []; @@ -22,6 +21,10 @@ export class CodeActionWrap implements CodeActionProvider { title: "Wrap with ValueListenableBuilder", }, /* TODO: Convert between ListenableBuilder <--> ValueListenableBuilder */ + { + command: "flutter-plus.wrap-repaintboundary", + title: "Wrap with RepaintBoundary", + } ].map((c) => { let action = new CodeAction(c.title, CodeActionKind.Refactor); action.command = { diff --git a/src/commands/wrap-with.command.ts b/src/commands/wrap-with.command.ts index 288996f..e1c8bdb 100644 --- a/src/commands/wrap-with.command.ts +++ b/src/commands/wrap-with.command.ts @@ -16,6 +16,14 @@ const snippetValueListenableBuilder = (widget: string) => { )`; }; +const snippetRepaintBoundary = (widget: string) => { + return `RepaintBoundary( + child: ${widget}, +)`; +}; + export const wrapWithListenableBuilder = async () => wrapWith(snippetListenableBuilder); -export const wrapWithValueListenableBuilder = async () => wrapWith(snippetValueListenableBuilder); \ No newline at end of file +export const wrapWithValueListenableBuilder = async () => wrapWith(snippetValueListenableBuilder); + +export const wrapWithRepaintBoundary = async () => wrapWith(snippetRepaintBoundary); \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index bb5108c..7179791 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,6 +8,7 @@ import { import { sealedStates, wrapWithListenableBuilder, + wrapWithRepaintBoundary, wrapWithValueListenableBuilder, } from "./commands"; @@ -27,6 +28,7 @@ export function activate(context: vscode.ExtensionContext) { commands.registerCommand("flutter-plus.sealed-states", sealedStates), commands.registerCommand("flutter-plus.wrap-listenablebuilder", wrapWithListenableBuilder), commands.registerCommand("flutter-plus.wrap-valuelistenablebuilder", wrapWithValueListenableBuilder), + commands.registerCommand("flutter-plus.wrap-repaintboundary", wrapWithRepaintBoundary), languages.registerCodeActionsProvider( DART_MODE,