Flutter学习笔记

Flutter 自定义snippets

2019-07-26  本文已影响0人  王俏

cmd + shift + p 打开控制面板 输入snippets 选择dart -->打开dart.json

{

  "StatelessWidget": {

    "prefix": "sl",

    "body": [

      "class ${1:WidgetName} extends StatelessWidget {",

      "\t@override",

      "\tWidget build(BuildContext context) {",

      "\t\treturn ${2:Container}();",

      "\t}",

      "}"

    ],

    "description": "StatelessWidget"

  },

  "StatefulWidget": {

    "prefix": "sf",

    "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 ${2:Container}();",

      "\t}",

      "}"

    ],

    "description": "StatefulWidget"

  },

  "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"

  },

}
上一篇下一篇

猜你喜欢

热点阅读