这是indexloc提供的服务,不要输入任何密码

model_annotation 0.0.6 copy "model_annotation: ^0.0.6" to clipboard
model_annotation: ^0.0.6 copied to clipboard

Library used to generate code snippets for data extraction and conversion between Model and Entity

Usage #

dart pub run build_runner build --delete-conflicting-outputs

Configure #

import 'package:example/_model.dart';
import 'package:model_annotation/model_annotation.dart';

@ModelAnnotation()
class MyModel extends Model {
  @FieldAnnotation(parseJson: false)
  final int? id;
  final String? message;
  final DateTime? dateTime;

  MyModel(
    this.id, {
    required this.message,
    this.dateTime,
  });
}

File *.g.dart #

import 'my_model.dart';

class MyModelEntity {
  final int? id;
  final String? message;
  final DateTime? dateTime;

  MyModelEntity({
    this.id,
    this.message,
    this.dateTime,
  });

  factory MyModelEntity.fromJson(Map<String, dynamic> json) => MyModelEntity(
    message: json["message"] is String ? json["message"] : null,
    dateTime: DateTime.tryParse(json["dateTime"].toString()),
  );

  Map<String, dynamic> toJson() => {
    "message": message,
    "dateTime": dateTime,
  };

  MyModel toModel() => MyModel(
    id,
    message: message,
    dateTime: dateTime,
  );
}

1
likes
140
points
106
downloads

Publisher

unverified uploader

Weekly Downloads

Library used to generate code snippets for data extraction and conversion between Model and Entity

Repository (GitHub)
View/report issues

Topics

#json #generation #annotation #model

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

BSD-3-Clause (license)

Dependencies

analyzer, build, meta, source_gen

More

Packages that depend on model_annotation