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

discontinuedreplaced by: data_class_macro

Experimental support for data classes in Dart using pkg:macros

struct_annotation #

build pub package License: MIT

🚧 Experimental 🚧

Experimental support for data classes in Dart using macros.

✨ Features #

🪨 const constructors with required, named parameters

🖨️ copyWith with optional, nullable, named parameters

toString for an improved string representation

☯️ operator== and hashCode for value equality

🧑‍💻 Example #

import 'package:struct_annotation/struct_annotation.dart';

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

void main() {
  // 🪨 Create a const instance with required, name parameters.
  const jane = Person(name: 'Jane', age: 42);

  // 🖨️ Create copies of your object.
  final john = jane.copyWith(name: 'John');

  // ✨ Human-readable string representation.
  print(jane); // Person(name: Jane, age: 42)
  print(john); // Person(name: John, age: 42)

  // ☯️ Value equality comparisons.
  print(jane == jane.copyWith()); // true
  print(john == john.copyWith(age: 21)); // false
}

🚀 Quick Start #

  1. Switch to the Flutter master channel flutter channel master

  2. Add package:struct_annotation to your pubspec.yaml

    dependencies:
      struct_annotation: ^0.0.0-dev.1
    
  3. Enable experimental macros in analysis_options.yaml

    analyzer:
      enable-experiment:
        - macros
    
  4. Use the @Struct annotation (see above example).

  5. Run it

    dart --enable-experiment=macros run main.dart
    

*Requires Dart SDK >= 3.5.0-152.0.dev

11
likes
0
pub points
0%
popularity

Publisher

verified publisherbloc-dev.com

Experimental support for data classes in Dart using pkg:macros

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, equatable, macros

More

Packages that depend on struct_annotation