Search for "Dart Data Class Generator: Generate from class properties"
Select classes to generate when prompted
Note: You can run the generator on existing data classes to update them after property changes.
Generate from JSON (Beta)
Create an empty Dart file
Paste raw JSON into the file
Press Ctrl + P (or Cmd + P on macOS)
Search for "Dart Data Class Generator: Generate from JSON"
Enter name for the root class
Choose whether to separate nested classes into multiple files
Beta Warning: Numbers in JSON might be interpreted as int even if they should be double.
Working with Enums
To ensure enums are correctly serialized, annotate them:
// enum
final Enum myEnum;
Additional Features
The extension includes some additional quick fixes that might be useful to you:
Import refactoring
Sort imports alphabetically and bring them into the correct format easily.
Settings
You can customize the generator to only generate the functions you want in your settings file.
dart_data_class_generator.quick_fixes: If true, enables quick fixes to quickly generate data classes or specific methods only.
dart_data_class_generator.useEquatable: If true, uses Equatable for value equality and hashCode.
dart_data_class_generator.useEquatableMixin: If true, uses equatableMixin for value equality and hashcode.(dart_data_class_generator.useEquatable must be true)
dart_data_class_generator.fromMap.default_values: If true, checks if a field is null when deserializing and provides a non-null default value.
dart_data_class_generator.constructor.default_values: If true, generates default values for the constructor.
dart_data_class_generator.constructor.required: If true, generates @required annotation for every constructor parameter. Note: The generator wont generate default values for the constructor if enabled!
dart_data_class_generator.json.seperate: Whether to seperate a JSON into multiple files, when the JSON contains nested objects. ask: choose manually every time, seperate: always seperate into multiple files, current_file: always insert all classes into the current file.
dart_data_class_generator.override.manual: If true, asks, when overriding a class (running the command on an existing class), for every single function/constructor that needs to be changed whether the generator should override the function or not. This allows you to preserve custom changes you made to the function/constructor that would be otherwise overwritten by the generator.
dart_data_class_generator.constructor.enabled: If true, generates a constructor for a data class.
dart_data_class_generator.copyWith.enabled: If true, generates a copyWith function for a data class.
dart_data_class_generator.toJson.enabled: If true, generates a toJson function for a data class.
dart_data_class_generator.fromJson.enabled: If true, generates a fromJson function for a data class.
dart_data_class_generator.toString.enabled: If true, generates a toString function for a data class.
dart_data_class_generator.equality.enabled: If true, generates an override of the == (equals) operator for a data class.
dart_data_class_generator.hashCode.enabled: If true, generates a hashCode function for a data class.
dart_data_class_generator.hashCode.use_jenkins: If true, uses the Jenkins SMI hash function instead of bitwise operator from dart:ui.