Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/felangel/data_class
Experimental support for data classes in Dart using macros.
https://github.com/felangel/data_class
dart data-class macros struct
Last synced: about 2 months ago
JSON representation
Experimental support for data classes in Dart using macros.
- Host: GitHub
- URL: https://github.com/felangel/data_class
- Owner: felangel
- License: mit
- Created: 2024-05-16T04:55:39.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-05-19T01:42:55.000Z (4 months ago)
- Last Synced: 2024-05-19T14:53:11.680Z (4 months ago)
- Topics: dart, data-class, macros, struct
- Language: Dart
- Homepage: https://pub.dev/packages/data_class_macro
- Size: 9.39 MB
- Stars: 163
- Watchers: 8
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# data_class
[![build](https://github.com/felangel/data_class/actions/workflows/main.yaml/badge.svg)](https://github.com/felangel/data_class/actions/workflows/main.yaml)
[![pub package](https://img.shields.io/pub/v/data_class.svg)](https://pub.dev/packages/data_class)
[![License: MIT](https://img.shields.io/badge/license-MIT-purple.svg)](https://opensource.org/licenses/MIT)**🚧 Experimental** support for data classes in Dart using [macros](https://dart.dev/language/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
```dart
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
}
```## 🚀 Quick Start
1. Switch to the Flutter `master` channel
`flutter channel master`1. Add `package:data_class` to your `pubspec.yaml`
```yaml
dependencies:
data_class: any
```1. Enable experimental macros in `analysis_options.yaml`
```yaml
analyzer:
enable-experiment:
- macros
```1. Use the `@Data` annotation (see above example).
1. Run it
```sh
dart --enable-experiment=macros run main.dart
```_\*Requires Dart SDK >= 3.5.0-152.0.dev_