John Wiese
John Wiese

Reputation: 1681

Support for 'Dart' snippets

I would like to support Dart snippets in VS Code. I'd also like to do so using something like the Snippet Creator (https://github.com/nikitaKunevich/vscode-snippet-creator) but this doesn't seem to work as 'dart' is not a language option. Is it possible to add 'dart' as an option so that I can use the snippet creator to have snippets in '*.dart' files?

Upvotes: 4

Views: 1452

Answers (1)

Shinwar ismail
Shinwar ismail

Reputation: 307

control+shift+p >snippets > dart.json add this code

{
    "stateless": {
      "prefix": "fless",
      "body": [
        "import 'package:flutter/material.dart';",
        "class $1 extends StatelessWidget {",
        "\t@override",
        "\tWidget build(BuildContext context) {",
        "\t\treturn Container(",
        "\t\t\t$2",
        "\t\t);",
        "\t}",
        "}"
      ]
    },

    "stateful": {
      "prefix": "ffull",
      "body": [
        "import 'package:flutter/material.dart';",
        "class $1 extends StatefulWidget {",
        "\t@override",
        " \t_$1State createState() => _$1State();",
        "}",

        "class _$1State extends State<$1> {",
        " \t@override",
        " \tWidget build(BuildContext context) {",
        "\t\treturn Container(",
        " \t\t\t$2",
        "\t\t);",
        "\t}",
        "} "
      ]
    }

} //control+shift+p >snippets > dart.json add this code

Upvotes: 2

Related Questions