为 Zed 编辑器 添加 flutter dart snippets

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 配置文件里面

json 复制代码
{
  "Flutter Stateless Widget": {
    "prefix": "sl",
    "body": [
      "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": [
      "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": "wwa",
    "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 Stateful Widget"
  },
  "StatelessWidget with Scaffold": {
    "prefix": "sls",
    "body": [
      "class ${1:WidgetName} extends StatelessWidget {",
      "\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": "StatelessWidget with Scaffold"
  },
  "StatefulWidget with Scaffold": {
    "prefix": "sfs",
    "body": [
      "class ${1:WidgetName} extends StatefulWidget {",
      "\t@override",
      "\t_${1:WidgetName}State createState() => _${1:WidgetName}State();",
      "}\n",
      "class _${1:WidgetName}State extends State<${1:WidgetName}> {",
      "\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": "StatefulWidget with Scaffold"
  },
  "InheritedWidget": {
    "prefix": "ih",
    "body": [
      "class ${1:WidgetName} extends InheritedWidget {",
      "\tfinal Widget child;",
      "\t${2}",
      "\t${1:WidgetName}({",
      "\t\tthis.child,",
      "\t\t${2}",
      "\t}) : super(child: child);\n",
      "\tstatic ${1:WidgetName} of(BuildContext context) =>",
      "\t\t\tcontext.inheritFromWidgetOfExactType(${1:WidgetName});\n",
      "\t@override",
      "\tbool updateShouldNotify(${1:WidgetName} oldWidget) {",
      "\t\treturn true;",
      "\t}",
      "}"
    ],
    "description": "InheritedWidget"
  },
  "setState": {
    "prefix": "ss",
    "body": ["setState(() {${1}});"],
    "description": "setState"
  },
  "build": {
    "prefix": "build",
    "body": [
      "@override",
      "Widget build(BuildContext context) {",
      "\treturn ${1:Container}(${2});",
      "}"
    ],
    "description": "Build Method"
  }
}

其中前三个是 和 vscodeflutter 扩展带来的 snippets 完全一致, 即在vscode里面打开 .dart为后缀的文件,输入小写 字母 s 触发,新建的 .dart 文件需要保存一下, 你要安装的有 flutter 扩展。

相关推荐
云水一下7 小时前
TypeScript 从零基础到精通(五):高级类型与泛型
前端·javascript·typescript
counterxing7 小时前
vibe coding 之后,我更不想打字了
前端·agent·ai编程
copyer_xyf7 小时前
Python 模块与包的导入导出
前端·后端·python
研☆香8 小时前
es6新特性功能介绍(四)
前端·ecmascript·es6
微扬嘴角8 小时前
React篇1--JSX语法规则、组件、组件实例的3大特性
前端·react.js·前端框架
copyer_xyf8 小时前
Python venv 虚拟环境
前端·后端·python
无聊的老谢8 小时前
Vue 3 + TypeScript 构建大型电信运维平台的前端架构设计
前端·vue.js·typescript
xiaofeichaichai8 小时前
Map / Set / WeakMap / WeakSet
前端·javascript
李可以量化8 小时前
成交量的终极量化策略:价量共振指标完整实现(下篇)
前端·数据库·人工智能
copyer_xyf9 小时前
Python 如何同时做很多事:进程、线程、协程
前端·后端·python