Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] VS Code snippet to generate basic layout of freezed model class #85

Closed
orestesgaolin opened this issue Mar 3, 2020 · 7 comments

Comments

@orestesgaolin
Copy link
Contributor

It would be useful to have a VS Code snippet to generate basic layout of the model class. It's easy to forget about some parts such as part or abstract.

Did anyone create such snippet? I would love to use one.

@rrousselGit
Copy link
Owner

rrousselGit commented Mar 3, 2020

I think @ResoCoder did

@orestesgaolin
Copy link
Contributor Author

Ok, I tried on my own and this is my proposal:

	"Generate freezed class": {
		"prefix": "freezed",
		"body": [
			"import 'package:freezed_annotation/freezed_annotation.dart';",
			"",
			"part '$1.freezed.dart';",
			"",
			"@freezed",
			"abstract class $2 with _$$2 {",
			"factory $2() = _$2;",
			"}"
		]
	}

@mono0926
Copy link
Sponsor Contributor

mono0926 commented Mar 3, 2020

I think @ResoCoder did

Here it is:
Freezed ❄ – Data Class & Union in One Dart Package - Reso Coder

@ResoDev
Copy link

ResoDev commented Mar 3, 2020

Here are all the snippets which you may find useful when working with Freezed.

"Part statement": {
    "prefix": "pts",
    "body": [
      "part '${TM_FILENAME_BASE}.g.dart';",
    ],
    "description": "Creates a filled-in part statement"
  },
  "Part 'Freezed' statement": {
    "prefix": "ptf",
    "body": [
      "part '${TM_FILENAME_BASE}.freezed.dart';",
    ],
    "description": "Creates a filled-in freezed part statement"
  },
  "Freezed Data Class": {
    "prefix": "fdataclass",
    "body": [
      "@freezed",
      "abstract class ${1:DataClass} with _$${1:DataClass}{",
      "  const factory ${1:DataClass}(${2}) = _${1:DataClass};",
      "}"
    ],
    "description": "Freezed Data Class"
  },
  "Freezed Union": {
    "prefix": "funion",
    "body": [
      "@freezed",
      "abstract class ${1:Union} with _$${1:Union}{",
      "  const factory ${1:Union}.${2}(${4}) = ${3};",
      "}"
    ],
    "description": "Freezed Union"
  },
  "Freezed Union Case": {
    "prefix": "funioncase",
    "body": [
      "const factory ${1:Union}.${2}(${4}) = ${3};"
    ],
    "description": "Freezed Union Case"
  },
  "From JSON": {
    "prefix": "fromJson",
    "body": [
      "factory ${1}.fromJson(Map<String, dynamic> json) => _$${1}FromJson(json);"
    ],
    "description": "From JSON"
  },

@knaeckeKami

This comment has been minimized.

@rrousselGit
Copy link
Owner

Closing this since there are quite a few solutions and I don't want to maintain these myself.

@lulupointu
Copy link

lulupointu commented Apr 9, 2021

Here is an updated template for Android Studio/Intelli, in complement to the one of @knaeckeKami it will:

  • Not use the abstract keyword which is no longer needed
  • Use the file name to complete everything, no need to write anything
  • Put you cursor at your class arguments

To add this template:

  1. Download freezed_extended_template.zip
  2. Choose File | Manage IDE Settings | Import Settings from the menu.
  3. Specify the path to the archive with the exported live template configuration downloaded in 1.
  4. In the Import Settings dialog, select the Live templates checkbox and click OK.
  5. After restarting IntelliJ IDEA, you will see the imported live templates on the Editor | Live Templates page of the Settings/Preferences Ctrl+Alt+S under the name Freezed Extended.
  6. You can start using the snippet by typing freezed

PS: thanks for the plugin !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants