equatable_macro 0.0.1-main.1 copy "equatable_macro: ^0.0.1-main.1" to clipboard
equatable_macro: ^0.0.1-main.1 copied to clipboard

A Dart library providing a macro for automatic implementation of the Equatable

example/equatable_macro_example.dart

import 'package:equatable_macro/equatable_macro.dart';

void main() {
  var a = Example(1, 'Alice');
  var b = Example(1, 'Alice');
  var c = Example(2, 'Bob');

  // equals
  print(a == b); // true
  print(a == c); // false
  // hashCode
  print(a.hashCode); // Unique hashCode based on fields
  print(b.hashCode); // Same hashCode as 'a'
  print(c.hashCode); // Different hashCode from 'a' and 'b'
  // toString
  print(a); // Example(id: 1, name: Alice)
  print(b); // Example(id: 1, name: Alice)
  print(c); // Example(id: 2, name: Bob)
}

@Equatable(stringify: true)
class Example {
  final int id;
  final String name;

  const Example(this.id, this.name);
}
0
likes
140
points
25
downloads
screenshot

Publisher

verified publishertakeitall.news

Weekly Downloads

A Dart library providing a macro for automatic implementation of the Equatable

Repository (GitHub)
View/report issues
Contributing

Topics

#equatable #macros #utilities #hascode #equality

Documentation

Documentation
API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

collection, macros

More

Packages that depend on equatable_macro