zed 添加 snippets 和 vscode 的 snippets 看起来非常的像,官方文档示例地址如下:zed.dev/docs/snippe…
参考了 宁浩 老师的 vscode snippets : github.com/ninghao/vsc…
为 zed 添加 snipptes 步骤如下:
command + shift + p或者用 菜单go->command palette..., 然后输入snippets: configure snippets回车确定
select snippets scope输入dart
回车确定会打开 dart.json, 把如下代码复制粘贴进入你 zed 配置文件里面
{
"Flutter Inherited Widget": {
"prefix": "ih",
"body": [
"import 'package:flutter/material.dart';\n",
"class ${1:MyWidget} extends InheritedWidget {",
"\tconst ${1:MyWidget}({",
"\t\tsuper.key,",
"\t\trequired super.child",
"\t});\n",
"\tstatic ${1:MyWidget}? of(BuildContext context) =>",
"\t\tcontext.dependOnInheritedWidgetOfExactType<${1:MyWidget}>();\n",
"\t@override",
"\tbool updateShouldNotify(${1:MyWidget} oldWidget) {",
"\t\treturn true;",
"\t}",
"}"
],
"description": "Flutter Inherited Widget"
},
"Flutter Stateless Widget": {
"prefix": "sl",
"body": [
"import 'package:flutter/material.dart';\n",
"class ${1:MyWidget} extends StatelessWidget {",
"\tconst ${1:MyWidget}({super.key});",
"\t@override",
"\tWidget build(BuildContext context) {",
"\t\treturn const ${2:Placeholder}();",
"\t}",
"}"
],
"description": "Flutter Stateless Widget"
},
"Flutter Stateful Widget": {
"prefix": "sf",
"body": [
"import 'package:flutter/material.dart';\n",
"class ${1:MyWidget} extends StatefulWidget {",
"\tconst ${1:MyWidget}({super.key});\n",
"\t@override",
"\tState<${1:MyWidget}> createState() => _${1:MyWidget}State();",
"}\n",
"class _${1:MyWidget}State extends State<${1:MyWidget}> {",
"\t@override",
"\tWidget build(BuildContext context) {",
"\t\treturn const ${2:Placeholder}();",
"\t}",
"}"
],
"description": "Flutter Stateful Widget"
},
"Flutter Widget with AnimationController": {
"prefix": "sfwa",
"body": [
"class ${1:MyWidget} extends StatefulWidget {",
"\tconst ${1:MyWidget}({super.key});\n",
"\t@override",
"\tState<${1:MyWidget}> createState() => _${1:MyWidget}State();",
"}\n",
"class _${1:MyWidget}State extends State<${1:MyWidget}>",
" with SingleTickerProviderStateMixin {",
"\tlate AnimationController _controller;\n",
"\t@override",
"\tvoid initState() {",
"\t\tsuper.initState();",
"\t\t_controller = AnimationController(vsync: this);",
"\t}\n",
"\t@override",
"\tvoid dispose() {",
"\t\t_controller.dispose();",
"\t\tsuper.dispose();",
"\t}\n",
"\t@override",
"\tWidget build(BuildContext context) {",
"\t\treturn const ${2:Placeholder}();",
"\t}",
"}"
],
"description": "Flutter Widget with AnimationController"
},
"Flutter Stateless Widget with Scaffold": {
"prefix": "slws",
"body": [
"import 'package:flutter/material.dart';\n",
"class ${1:MyWidget} extends StatelessWidget {",
"\tconst ${1:MyWidget}({super.key});\n",
"\t@override",
"\tWidget build(BuildContext context) {",
"\t\treturn Scaffold(",
"\t\t\tappBar: AppBar(",
"\t\t\t\ttitle: Text('${1:MyWidget}'),",
"\t\t\t\televation: 0.0,",
"\t\t\t),${2}",
"\t\t);",
"\t}",
"}"
],
"description": "Flutter Stateless Widget with Scaffold"
},
"Flutter Statefull Widget with Scaffold": {
"prefix": "sfws",
"body": [
"import 'package:flutter/material.dart';\n",
"class ${1:MyWidget} extends StatefulWidget {",
"\tconst ${1:MyWidget}({super.key});\n",
"\t@override",
"\tState<${1:MyWidget}> createState() => _${1:MyWidget}State();",
"}\n",
"class _${1:MyWidget}State extends State<${1:MyWidget}> {",
"\t@override",
"\tWidget build(BuildContext context) {",
"\t\treturn Scaffold(",
"\t\t\tappBar: AppBar(",
"\t\t\t\ttitle: Text('${1:WidgetName}'),",
"\t\t\t\televation: 0.0,",
"\t\t\t),${2}",
"\t\t);",
"\t}",
"}"
],
"description": "Flutter Statefull Widget with Scaffold"
}
}
其中前三个是 和 vscode 的 flutter 扩展带来的 snippets 完全一致,
即在vscode里面打开 .dart为后缀的文件,输入小写 字母 s 触发,新建的 .dart 文件需要保存一下, 你要安装的有 flutter 扩展。