Skip to content

Instantly share code, notes, and snippets.

@timnew
Created November 16, 2022 00:54
Show Gist options
  • Save timnew/927767536569e21d87c78a65f5b69256 to your computer and use it in GitHub Desktop.
Save timnew/927767536569e21d87c78a65f5b69256 to your computer and use it in GitHub Desktop.
VSCode Code snippet for Dart and Flutter
{
"for": {
"prefix": "for",
"body": ["for(int ${1:i} = ${2:0}; $1 < $3; $1++){", " $4", "}"],
"description": "For loop"
},
"fore": {
"prefix": "fore",
"body": ["for(final ${1:item} in ${2: list}){", " $3", "}"],
"description": "for each"
},
"cl": {
"prefix": "cl",
"body": ["class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} {", " const $1();", " $2", "}"],
"description": "Stateless Widget"
},
"wl": {
"prefix": "wl",
"body": [
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} extends StatelessWidget {",
" const $1({super.key});",
"",
" @override",
" Widget build(BuildContext context) =>",
" const Text(\"$1\");",
"}"
],
"description": "Stateless Widget"
},
"wsc": {
"prefix": "wsc",
"body": [
"import 'package:flutter/material.dart';",
"",
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} extends StatelessWidget {",
" const $1({super.key});",
"",
" @override",
" Widget build(BuildContext context) => Scaffold(",
" appBar: AppBar(",
" title: const Text(\"$1\"),",
" ),",
" );",
"}"
],
"description": "Screen"
},
"ws": {
"prefix": "ws",
"body": [
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} extends StatefulWidget {",
" const $1({super.key});",
"",
" @override",
" _$1State createState() => _$1State();",
"}",
"",
"class _$1State extends State<$1> {",
" @override",
" Widget build(BuildContext context) =>",
" const Text(\"$1\");",
"}"
],
"description": "Stateful Widget"
},
"fwm": {
"prefix": "fwm",
"body": [
"import 'package:flutter/material.dart';",
],
"description": "Material Widget"
},
"gr": {
"prefix": "gr",
"body": [
"${1:Group} (",
" children: [",
" $2",
" ],",
"),",
],
"description": "Container"
},
"sbh":{
"prefix": "sbh",
"body": [
"const SizedBox(height: ${1:8}),$2",
],
"description": "const SizedBox with height"
},
"sbw":{
"prefix": "sbw",
"body": [
"const SizedBox(width: ${1:8}),$2",
],
"description": "const SizedBox with width"
},
"thof": {
"prefix": "thof",
"body": ["Theme.of(context)"],
"description": "Theme of"
},
"tthof": {
"prefix": "tthof",
"body": ["style: Theme.of(context).textTheme"],
"description": "Text Theme of"
},
"alf": {
"prefix": "alf",
"body": "import 'package:flutter_gen/gen_l10n/app_localizations.dart';",
"description": "Localization - import AppLocalizations"
},
"alof": {
"prefix": "alof",
"body": "AppLocalizations.of(context)!",
"description": "Localization - reference AppLocalizations"
},
"main": {
"prefix": "main",
"body": ["void main() {", " $1", "}"],
"description": "Main fuction"
},
"mainft": {
"prefix": "mainft",
"body": [
"import 'package:flutter_test/flutter_test.dart';",
"",
"void main() {",
" group(\"${1:${TM_FILENAME_BASE/(.*)_test/${1:/pascalcase}/}}\", () {",
" $2",
" });",
"}"
],
"description": "Test file"
},
"grt": {
"prefix": "grt",
"body": ["group(\"${1:description}\", () {", " $2", "});"],
"description": "Test group"
},
"testd": {
"prefix": "testd",
"body": ["test(\"${1:description}\", () {", " $2", "});"],
"description": "Unit Test"
},
"testa": {
"prefix": "testa",
"body": ["test(\"${1:description}\", () async {", " $2", "});"],
"description": "Unit Test - Async"
},
"testw": {
"prefix": "testw",
"body": ["testWidgets(\"${1:description}\", (WidgetTester tester) async {", " $2", "});"],
"description": "Unit Test - Widget"
},
"setup": {
"prefix": "setup",
"body": ["setUp(() {", " $1", "});"],
"description": "Unit Test - Setup"
},
"setupa": {
"prefix": "setupa",
"body": ["setUpAll(() {", " $1", "});"],
"description": "Unit Test - Setup All"
},
"tear": {
"prefix": "tear",
"body": ["tearDown(() {", " $1", "});"],
"description": "Unit Test - Tear down"
},
"teara": {
"prefix": "teara",
"body": ["tearDownAll(() {", " $1", "});"],
"description": "Unit Test - Teardown All"
},
"pumpw": {
"prefix": "pumpw",
"body": ["await tester.pumpWidget(${1:widget});", ""],
"description": "Unit Test - Pump Widget"
},
"pumpws": {
"prefix": "pumpws",
"body": ["await tester.pumpWidgetOnScaffold(${1:widget});", ""],
"description": "Unit Test - Pump Widget on scaffold"
},
"pump": {
"prefix": "pump",
"body": ["await tester.pump();"],
"description": "Unit Test - Pump"
},
"pumpz": {
"prefix": "pumpz",
"body": ["await tester.pump(Duration.zero);"],
"description": "Unit Test - Pump with Duration.zero to ensure async stream run"
},
"runasync": {
"prefix": "runasync",
"body": ["await tester.runAsync(() async {", " $1", "});", "await tester.pump();"],
"description": "Unit Test - Run Async"
},
"expt": {
"prefix": "expt",
"body": ["expect($1, $2);"],
"description": "Unit Test - Expect"
},
"exptn": {
"prefix": "exptn",
"body": ["expect(() => $1, returnsNormally);"],
"description": "Unit Test - Expect no error"
},
"exptt": {
"prefix": "exptt",
"body": ["expect(() => $1, throws$2);"],
"description": "Unit Test - Expect throws"
},
"expl": {
"prefix": "exptl",
"body": ["await expectLater($1, $2);"],
"description": "Unit Test - ExpectLater"
},
"explc": {
"prefix": "explc",
"body": ["await expectLater($1, completion($2));"],
"description": "Unit Test - ExpectLater completion"
},
"explt": {
"prefix": "explt",
"body": ["await expectLater($1, throwsA($2));"],
"description": "Unit Test - ExpectLater completion"
},
"frf": {
"prefix": "frf",
"body": [
"import 'package:freezed_annotation/freezed_annotation.dart';",
"",
"part '$TM_FILENAME_BASE.freezed.dart';",
""
],
"description": "Frezed - file"
},
"frfjson": {
"prefix": "frfjson",
"body": ["part '$TM_FILENAME_BASE.g.dart';", ""],
"description": "Frezed - file json"
},
"frd": {
"prefix": "frd",
"body": [
"@freezed",
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} with _$$1 {",
" const factory $1({$2}) = _$1;",
"}",
""
],
"description": "Freezed - Class"
},
"frjson": {
"prefix": "frjson",
"body": [
"factory ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}.fromJson(Map<String, dynamic> json) => _$$1FromJson(json);",
""
],
"description": "Freezed - Json Constructor"
},
"fre": {
"prefix": "fre",
"body": [
"@freezed",
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} with _$$1 {",
" const $1._();",
"",
" const factory ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}.$2() = ${4:${2/(.*)/${1:/pascalcase}/}}$5;",
"",
"$6",
"}"
],
"description": "Freezed - Enum Type delcaration"
},
"fref": {
"prefix": "fref",
"body": [
"const factory ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}.$2() = ${4:${2/(.*)/${1:/pascalcase}/}}$5;",
"",
"$6"
],
"description": "Freezed - Enum Type constructor"
},
"frefd": {
"prefix": "frefd",
"body": [
"const factory ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}.$2(${3:{}}) = ${4:${2/(.*)/${1:/pascalcase}/}}$5;",
"",
"$6"
],
"description": "Freezed - Enum Type constructor with data"
},
"bvf": {
"prefix": "bvf",
"body": ["import 'package:built_value/built_value.dart';", "", "part '$TM_FILENAME_BASE.g.dart';", ""],
"description": "BuiltValue - file"
},
"bvd": {
"prefix": "bvd",
"body": [
"abstract class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} implements Built<$1, $1Builder> {",
" const $1._();",
" const factory $1([void Function($1Builder) updates]) = _$$1;",
"}",
""
],
"description": "BuiltValue - Class"
},
"rtf": {
"prefix": "rtf",
"body": [
"import 'package:dio/dio.dart';",
"import 'package:retrofit/retrofit.dart';",
"",
"part '$TM_FILENAME_BASE.g.dart';",
""
],
"description": "Retrofit - File declaration"
},
"rtd": {
"prefix": "rtd",
"body": [
"@RestApi(baseUrl: \"${2:https://}\")",
"abstract class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} {",
" factory $1(Dio dio, {String baseUrl}) = _$1;",
"",
" @GET(\"$3\")",
" Future<${4:Map<String, dynamic>}> ${5:getData}();",
"",
"}"
],
"description": "Retrofit - Api Class"
},
"mobf": {
"prefix": "mobf",
"body": [
"import 'package:mobx/mobx.dart';",
"",
"part '$TM_FILENAME_BASE.g.dart';",
""
],
"description": "Mobx - file"
},
"mobs": {
"prefix": "mobs",
"body": [
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}Store/}} = _$1 with _$$1;",
"",
"abstract class _$1 with Store {",
" $2",
"}",
""
],
"description": "Mobx - store"
},
"csd": {
"prefix": "csd",
"body": [ "// cSpell:disable" ],
"description": "CSpell - disable"
},
"cse": {
"prefix": "cse",
"body": [ "// cSpell:enable" ],
"description": "CSpell - enable"
},
"csdl": {
"prefix": "csdl",
"body": [ "// cSpell:disable-line" ],
"description": "CSpell - disable current line"
},
"csdnl": {
"prefix": "csdnl",
"body": [ "// cSpell:disable-next-line" ],
"description": "CSpell - disable next line"
},
"csi": {
"prefix": "csi",
"body": [ "// cSpell:ignore ${1:aaa,bbb}" ],
"description": "CSpell - ignore words"
},
"csireg": {
"prefix": "csireg",
"body": [ "// cSpell:ignoreRegExp ${1:Base64}" ],
"description": "CSpell - ignore RegExp"
},
"csw": {
"prefix": "csw",
"body": [ "// cSpell:words ${1:aaa bbb ccc}" ],
"description": "CSpell - words"
},
"csc": {
"prefix": "csc",
"body": [ "// cSpell:enableCompoundWords" ],
"description": "CSpell - enable compound words"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment