struct_annotation 0.0.0-dev.5 copy "struct_annotation: ^0.0.0-dev.5" to clipboard
struct_annotation: ^0.0.0-dev.5 copied to clipboard

Experimental support for data classes in Dart using pkg:macros

example/main.dart

// TODO(felangel): remove once https://github.com/dart-lang/sdk/commit/73bdc86dd50e11cedb3bf976c597a02ad209bdb4 lands on master
// ignore: unnecessary_import
import 'package:struct_annotation/src/struct_annotation.dart';
import 'package:struct_annotation/struct_annotation.dart';

@Struct()
class Person {
  final String name;
}

void main() {
  // 🪨 Create a const instance with required, name parameters.
  const dash = Person(name: 'Dash');

  // 🖨️ Create copies of your object.
  final sparky = dash.copyWith(name: () => 'Sparky');

  // ✨ Human-readable string representation.
  print(dash); // Person(name: Dash)
  print(sparky); // Person(name: Sparky)

  // ☯️ Value equality comparisons.
  print(dash == dash.copyWith()); // true
  print(dash == sparky); // false
}
11
likes
140
pub points
0%
popularity

Publisher

verified publisherbloc-dev.com

Experimental support for data classes in Dart using pkg:macros

Repository (GitHub)
View/report issues

Topics

#macros #data-class #struct

Documentation

API reference

License

MIT (license)

Dependencies

collection, macros

More

Packages that depend on struct_annotation