Skip to content

Instantly share code, notes, and snippets.

@timnew
Last active November 16, 2022 00:50
Show Gist options
  • Save timnew/f16cfbe2888d546291919d34b5248d70 to your computer and use it in GitHub Desktop.
Save timnew/f16cfbe2888d546291919d34b5248d70 to your computer and use it in GitHub Desktop.
VSCode Code Snippet for Freezed and Dart

How to use the snippets

  • frf is used to create the file header of the dart file contains freezed model
  • frfjson is used after frf as file header when json is used
  • frd is used to create a freezed model class (name is aligned to file name by default)
  • frjson is used to create fromJson constructor, which mark the model to be json serializable
  • fre is used to create an enumeration class
  • fref is used to create parameter-less case in enumeration class
  • frefd is used to create parametered case in enumeration class
{
"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"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment