vm_class_gen 3.1.1+6 copy "vm_class_gen: ^3.1.1+6" to clipboard
vm_class_gen: ^3.1.1+6 copied to clipboard

Generator for `VmClass`.

VmClassGen #

The builder generate code when they find members annotated with classes defined in vm_class_annotation.

A Dart library for creating enhanced object representations, with capabilities like custom toString, automated property management, and more. Ideal for developers looking to streamline their object model logic.

Overview #

VmClassGen provides a robust architecture for handling Dart objects, extending functionality with a focus on string representation, equality checks, and easy serialization.

Features #

  • Custom toString Implementations: Generate detailed or short string representations automatically.
  • Enhanced Equality Checks: Built on top of Equatable for robust comparison.
  • Flexible Code Generation: Use annotations to automate boilerplate code creation.

Quick Start #

Usage #

Generate property-centric classes with the VmClassGen annotation:

import 'package:vm_class/vm_class.dart';

part 'example.g.dart';

@VmClassGen()
class Address extends VmClass {
  const Address({
    required this.street,
    required this.city,
  });

  final String street;
  final String city;

  @override
  String? get shortQualifier => '$city, $street';

  @override
  Map<String, dynamic> get toStringProps => _$AddressStringProps(this);
}

void main() {
  final address = Address(street: '123 Main St', city: 'Metropolis');
  print(address.toString());
}

Building creates the corresponding part example.g.dart:

Map<String, dynamic> _$AddressStringProps(Address instance) => {
      'street': instance.street,
      'city': instance.city,
    };

For actual result, see vm_class.