Skip to main content

charcoal 0.0.3 copy "charcoal: ^0.0.3" to clipboard
charcoal: ^0.0.3 copied to clipboard

Unified annotation for generating ultra-fast JSON, copy, equals, hash code, and toString, with the type graph resolved at build time.

example/example.md

Example #

Add the dependencies:

dart pub add charcoal dev:charcoal_builder dev:build_runner

Annotate a class and add its generated mixin, in lib/book.dart:

import 'package:charcoal/charcoal.dart';

part 'book.charcoal.g.dart';

@Charcoal()
final class const Book({
  required this.title,
  required this.pages,
  required this.rating,
  required this.isHardcover,
  this.note,
}) with BookCharcoal {
  final String title;
  final int pages;
  final double rating;
  final bool isHardcover;
  final String? note;
}

Generate the code:

dart run build_runner build

Then use it, in bin/main.dart:

import 'dart:io';

import 'package:charcoal_example/book.dart';

void main() {
  const book = Book(title: 'Dune', pages: 420, rating: 4.5, isHardcover: true);
  final json = book.toJsonString();
  stdout.writeln(json);
  stdout.writeln(BookCharcoal.fromJsonString(json).title);
}

The full project is in the example folder.

1
likes
0
points
1.27k
downloads

Publisher

unverified uploader

Weekly Downloads

Unified annotation for generating ultra-fast JSON, copy, equals, hash code, and toString, with the type graph resolved at build time.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on charcoal