data_class

Creator: coderz1093

Last updated:

Add to Cart

Description:

data class

data_class #



🚧 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:data_class/data_class.dart';

@Data()
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
}
copied to clipboard
🚀 Quick Start #


Switch to the Flutter master channel
flutter channel master


Add package:data_class to your pubspec.yaml
dependencies:
data_class: any
copied to clipboard


Enable experimental macros in analysis_options.yaml
analyzer:
enable-experiment:
- macros
copied to clipboard


Use the @Data annotation (see above example).


Run it
dart --enable-experiment=macros run main.dart
copied to clipboard


*Requires Dart SDK >= 3.5.0-152.0.dev

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.