artifact 1.0.2 copy "artifact: ^1.0.2" to clipboard
artifact: ^1.0.2 copied to clipboard

Data Modeling for the local madman

example/lib/example.dart

import 'dart:convert';

import 'package:artifact/artifact.dart';
import 'package:example/gen/artifacts.gen.dart';

@artifact
class AllFields {
  final AnyEnum? e;

  @codec(RemoteCodec())
  final Remote remoteClass;

  final int x;
  final String? str;
  final double doub;

  const AllFields({
    required this.remoteClass,
    this.e = AnyEnum.a,
    required this.x,
    this.str,
    this.doub = 3,
  });
}

class Remote {
  final int i;
  const Remote(this.i);
}

class RemoteCodec extends ArtifactCodec<int, Remote> {
  const RemoteCodec();
  @override
  Remote? decode(int? value) => value == null ? null : Remote(value);

  @override
  int? encode(Remote? value) => value?.i;
}

enum AnyEnum { a, b, c, d }

void main() {
  print(
    jsonEncode(
      jsonDecode(
        AllFields(x: -6, remoteClass: Remote(7), e: AnyEnum.c).toJson(),
      ),
    ),
  );
}
0
likes
0
points
10
downloads

Publisher

verified publisherarcane.art

Weekly Downloads

Data Modeling for the local madman

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, build, fast_log, glob, source_gen, toxic

More

Packages that depend on artifact