84 lines
2.0 KiB
Dart
84 lines
2.0 KiB
Dart
class ResponseModel<T> {
|
|
T? data;
|
|
Meta? meta;
|
|
Links? links;
|
|
|
|
ResponseModel({this.data, this.meta, this.links});
|
|
|
|
ResponseModel.fromJson(
|
|
Map<String, dynamic> json, T Function(dynamic) fromJsonT) {
|
|
data = json['data'] != null ? fromJsonT(json['data']) : null;
|
|
meta = json['meta'] != null ? Meta.fromJson(json['meta']) : null;
|
|
links = json['links'] != null ? Links.fromJson(json['links']) : null;
|
|
}
|
|
|
|
Map<String, dynamic> toJson(Map<String, dynamic> Function(T) toJsonT) {
|
|
final Map<String, dynamic> data = <String, dynamic>{};
|
|
if (this.data != null) {
|
|
data['data'] = toJsonT(this.data as T);
|
|
}
|
|
if (meta != null) {
|
|
data['meta'] = meta!.toJson();
|
|
}
|
|
if (links != null) {
|
|
data['links'] = links!.toJson();
|
|
}
|
|
return data;
|
|
}
|
|
}
|
|
|
|
class Meta {
|
|
int? itemsPerPage;
|
|
int? totalItems;
|
|
int? currentPage;
|
|
int? totalPages;
|
|
List<List<String>>? sortBy;
|
|
|
|
Meta(
|
|
{this.itemsPerPage,
|
|
this.totalItems,
|
|
this.currentPage,
|
|
this.totalPages,
|
|
this.sortBy});
|
|
|
|
Meta.fromJson(Map<String, dynamic> json) {
|
|
itemsPerPage = json['itemsPerPage'];
|
|
totalItems = json['totalItems'];
|
|
currentPage = json['currentPage'];
|
|
totalPages = json['totalPages'];
|
|
if (json['sortBy'] != null) {
|
|
sortBy = (json['sortBy'] as List)
|
|
.map((item) => (item as List).map((e) => e.toString()).toList())
|
|
.toList();
|
|
}
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final Map<String, dynamic> data = <String, dynamic>{};
|
|
data['itemsPerPage'] = itemsPerPage;
|
|
data['totalItems'] = totalItems;
|
|
data['currentPage'] = currentPage;
|
|
data['totalPages'] = totalPages;
|
|
if (sortBy != null) {
|
|
data['sortBy'] = sortBy!.map((v) => v).toList();
|
|
}
|
|
return data;
|
|
}
|
|
}
|
|
|
|
class Links {
|
|
String? current;
|
|
|
|
Links({this.current});
|
|
|
|
Links.fromJson(Map<String, dynamic> json) {
|
|
current = json['current'];
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final Map<String, dynamic> data = <String, dynamic>{};
|
|
data['current'] = current;
|
|
return data;
|
|
}
|
|
}
|