Skip to content

Instantly share code, notes, and snippets.

@junsuk5
Created August 20, 2022 05:04
Show Gist options
  • Save junsuk5/65c33a75ba8c6775efba46d4fa183006 to your computer and use it in GitHub Desktop.
Save junsuk5/65c33a75ba8c6775efba46d4fa183006 to your computer and use it in GitHub Desktop.
Flutter VS Code snippets
{
"Generate class for new model": {
"prefix": "dataclass",
"scope": "dart",
"body": [
"import 'package:freezed_annotation/freezed_annotation.dart';",
"",
"part '${1/(^[A-Z][a-z]*|[a-z])([A-Z])?/${1:/downcase}${2:+_}${2:/downcase}/g}.freezed.dart';",
"",
"part '${1/(.*)/${1:/downcase}/}.g.dart';",
"",
"@freezed",
"class ${1:CAP_NAME} with _$$${1:CAP_NAME} {",
" const factory ${1:CAP_NAME}({",
" $0",
" }) = _${1:CAP_NAME};",
"",
" factory ${1:CAP_NAME}.fromJson(Map<String, Object?> json) => _$$${1:CAP_NAME}FromJson(json);",
"}$2",
],
"description": "",
}
}
{
"Generate class for new model": {
"prefix": "json",
"scope": "dart",
"body": [
"import 'package:json_annotation/json_annotation.dart';",
"",
"part '${1/(.*)/${1:/downcase}/}.g.dart';",
"@JsonSerializable(explicitToJson: true)",
"class ${1:CAP_NAME} {",
" $0",
"",
" ${1:CAP_NAME}();",
"",
" factory ${1:CAP_NAME}.fromJson(Map<String, dynamic> json) => _$$${1:CAP_NAME}FromJson(json);",
"",
" Map<String, dynamic> toJson() => _$$${1:CAP_NAME}ToJson(this);",
"}",
],
"description": "",
}
}
{
"Generate class for new model": {
"prefix": "sealedclass",
"scope": "dart",
"body": [
"import 'package:freezed_annotation/freezed_annotation.dart';",
"",
"part '${1/(^[A-Z][a-z]*|[a-z])([A-Z])?/${1:/downcase}${2:+_}${2:/downcase}/g}.freezed.dart';",
"",
"@freezed",
"class ${1:CAP_NAME}<T> with _$$${1:CAP_NAME}<T> {",
" const factory ${1:CAP_NAME}.success(T data) = Success;",
" const factory ${1:CAP_NAME}.error(Exception e) = Error;",
"}",
],
"description": "",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment