8000 GitHub - pedromassango/struct: Experimental support for data classes in Dart using macros.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Experimental support for data classes in Dart using macros.

License

Notifications You must be signed in to change notification settings

pedromassango/struct

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

struct_annotation

pub package License: MIT

🚧 Experimental 🚧

Experimental support for data classes in Dart using macros.

import 'package:struct_annotation/struct_annotation.dart';

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

void main() {
  final jane = Person(name: 'Jane', age: 42);
  final john = jane.copyWith(name: 'John');

  print(jane); // Person(name: Jane, age: 42)
  print(john); // Person(name: John, age: 42)

  print(jane == jane.copyWith()); // true
  print(john == john.copyWith(age: 21)); // false
}

Try It

  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 expe 5563 rimental 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

About

Experimental support for data classes in Dart using macros.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 100.0%
0