Skip to content

Latest commit

 

History

History
64 lines (50 loc) · 1.77 KB

CODE_SNIPPETS.md

File metadata and controls

64 lines (50 loc) · 1.77 KB

Configure your IDE to help you declare freezed serializable models in the fastest way possible.

VSCode

For configuring VSCode with Code Snippets, check out this video tutorial.

Code Snippet

{
  "Serializable freezed model": {
    "prefix": "fmodel",
    "description": "Declare a serializable freezed model",
    "body": [
      "import 'package:freezed_annotation/freezed_annotation.dart';",
      "",
      "part '${TM_FILENAME_BASE}.freezed.dart';",
      "part '${TM_FILENAME_BASE}.g.dart';",
      "",
      "@freezed",
      "class ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g} with _$${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g} {",
      "  const factory ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}({",
      "    ${0}",
      "  }) = _${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g};",
      "",
      "  factory ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}.fromJson(Map<String, dynamic> json) => ",
      "      _$${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}FromJson(json);",
      "}"
    ]
  }
}

Android Studio / IntelliJ IDEA

For configuring Android Studio or IntelliJ IDEA with Live Template, check out this video tutorial.

Live Template

Text:

import 'package:freezed_annotation/freezed_annotation.dart';

part '$FILE_NAME$.freezed.dart';
part '$FILE_NAME$.g.dart';

@freezed
class $CLASS_NAME$ with _$$$CLASS_NAME$ {
  const factory $CLASS_NAME$ ({
    $END$
  }) = _$CLASS_NAME$;
  
  factory $CLASS_NAME$.fromJson(Map<String, dynamic> json) =>
    _$$$CLASS_NAME$FromJson(json);
}

Variables:

Name Value
FILE_NAME fileNameWithoutExtension()
CLASS_NAME capitalize(camelCase(fileNameWithoutExtension()))