data_builder 1.0.0
data_builder: ^1.0.0 copied to clipboard

Data builder is used to create an immutable data class with data_annotation

Data builder is used to create an immutable data class with data_annotation.

Usage #

A simple usage with nullSafety example:

import 'package:data_annotation/data_annotation.dart';

part 'example.data.dart';

enum ExampleEnum { example }

class Model {
  Model.fromJson(Map<String, dynamic> json);

  Map<String, dynamic> toJson() => {};
}

@data
abstract class ExampleDataClass with _$ExampleDataClass {
  const ExampleDataClass._();

  const factory ExampleDataClass({
    double? field,
    String? field1,
    int? field2,
    bool? field3,
    ExampleEnum? field4,
    @DataKey('model') Model? field5,
    Uri? field6,
    BigInt? field7,
    DateTime? field8,
    Duration? field9,
    @DataKey('models') List<Model>? field10,
    @DataKey('modelByKey') Map<String, Model>? field11,
  }) = _ExampleDataClass;

  factory ExampleDataClass.fromJson(Map<String, dynamic> json) =
  _ExampleDataClass.fromJson;

  Map<String, dynamic> toJson();
}

A simple usage without nullSafety example:

import 'package:data_annotation/data_annotation.dart';

part 'example.data.dart';

enum ExampleEnum { example }

class Model {
  Model.fromJson(Map<String, dynamic> json);

  Map<String, dynamic> toJson() => {};
}

@data
abstract class ExampleDataClass with _$ExampleDataClass {
  const ExampleDataClass._();

  const factory ExampleDataClass({
    double field,
    String field1,
    int field2,
    bool field3,
    ExampleEnum field4,
    @DataKey('model') Model field5,
    Uri field6,
    BigInt field7,
    DateTime field8,
    Duration field9,
    @DataKey('models') List<Model> field10,
    @DataKey('modelByKey') Map<String, Model> field11,
  }) = _ExampleDataClass;

  factory ExampleDataClass.fromJson(Map<String, dynamic> json) =
  _ExampleDataClass.fromJson;

  Map<String, dynamic> toJson();
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1
likes
95
pub points
2%
popularity

Publisher

jonathanvegas.tech

Data builder is used to create an immutable data class with data_annotation

Homepage

Documentation

API reference

License

MIT (LICENSE)

Dependencies

analyzer, build, data_annotation, source_gen, source_helper

More

Packages that depend on data_builder