Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Dart Class GeneratorNew to Visual Studio Code? Get it now.
Dart Class Generator

Dart Class Generator

Taha Darwish

|
62 installs
| (0) | Free
Create dart data classes easily, fast and without writing boilerplate or running code generation.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Dart Data Class Generator

Create Dart data classes quickly without writing boilerplate or running code generation.

✨ Features

Generate complete data classes with:

  • Constructor
  • copyWith method
  • toString method
  • toJson/fromJson methods
  • operator== and hashCode
  • Equatable integration

🚀 Getting Started

Generate from Class Properties

Class properties demo

Quick Fix (Single Class)

  1. Create a class with properties
  2. Place cursor on class name, constructor, or field
  3. Press Ctrl + . (or Cmd + . on macOS)
  4. Select desired generation option

Command (Multiple Classes)

  1. Press Ctrl + P (or Cmd + P on macOS)
  2. Search for "Dart Data Class Generator: Generate from class properties"
  3. 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)

JSON demo

  1. Create an empty Dart file
  2. Paste raw JSON into the file
  3. Press Ctrl + P (or Cmd + P on macOS)
  4. Search for "Dart Data Class Generator: Generate from JSON"
  5. Enter name for the root class
  6. 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.
  • dart_data_class_generator.final_class.enabled: If true, generates classes with the 'final class' keyword instead of just 'class'.
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft