vm_class_gen 2.0.2+4 copy "vm_class_gen: ^2.0.2+4" to clipboard
vm_class_gen: ^2.0.2+4 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 with _$AddressVmClass {
  final String street;
  final String city;

  Address({
    required this.street,
    required this.city,
  });

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

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

Building creates the corresponding part example.g.dart:

mixin _$AddressVmClass on VmClass {
  @override
  Map<String, dynamic> get toStringProps => {
        ...super.toStringProps,
        'street': street,
        'city': city,
      };

  String get street;
  String get city;
}

For actual result, see vm_class.