Skip to content

Data Contracts

Dustin Catap edited this page Nov 12, 2023 · 1 revision

Data contract classes are models that represents REST API response JSON body.

The project uses json_annotation to generate the serialization/deserialization code.

part 'post_data_contract.g.dart';

@JsonSerializable()
class PostDataContract extends JsonSerializableObject {
  const PostDataContract({required this.userId, required this.id, required this.title, required this.body});

  factory PostDataContract.fromJson(Map<String, dynamic> json) => _$PostDataContractFromJson(json);

  final int userId;

  final int id;

  final String title;

  final String body;
}

💡 TIP

Use the code snippet shortcut jsonc to create a data contract class.