美文网首页Flutter学习笔记
Flutter 自定义snippets

Flutter 自定义snippets

作者: 王俏 | 来源:发表于2019-07-26 10:27 被阅读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"
    
      },
    
    }
    

    相关文章

      网友评论

        本文标题:Flutter 自定义snippets

        本文链接:https://www.haomeiwen.com/subject/bscrrctx.html