mobile_skt/lib/models/base_response.dart

102 lines
2.2 KiB
Dart
Raw Normal View History

2024-10-16 09:48:17 +08:00
/// 封装http请求基础返回体
class BaseResponse {
int? code;
dynamic data;
String? message;
BaseResponse({this.code, this.data, this.message});
BaseResponse.fromJson(Map<String, dynamic> json) {
code = json['code'];
data = json['data'];
message = json['message'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['code'] = code;
data['data'] = data;
data['message'] = message;
return data;
}
}
/// 封装http请求基础返回体
class PaginationResponse {
int? code;
PaginationData? data;
String? message;
PaginationResponse({this.code, this.data, this.message});
PaginationResponse.fromJson(Map<String, dynamic> json) {
code = json['code'];
data = json['data'];
message = json['message'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['code'] = code;
data['data'] = data;
data['message'] = message;
return data;
}
}
class PaginationData {
PaginationData({
required this.items,
required this.meta,
});
final List<dynamic> items;
final Meta? meta;
factory PaginationData.fromJson(Map<String, dynamic> json) {
return PaginationData(
items: json["items"],
meta: json["meta"] == null ? null : Meta.fromJson(json["meta"]),
);
}
Map<String, dynamic> toJson() => {
"items": items,
"meta": meta?.toJson(),
};
}
class Meta {
Meta({
required this.totalItems,
required this.itemCount,
required this.itemsPerPage,
required this.totalPages,
required this.currentPage,
});
final int? totalItems;
final int? itemCount;
final int? itemsPerPage;
final int? totalPages;
final int? currentPage;
factory Meta.fromJson(Map<String, dynamic> json) {
return Meta(
totalItems: json["totalItems"],
itemCount: json["itemCount"],
itemsPerPage: json["itemsPerPage"],
totalPages: json["totalPages"],
currentPage: json["currentPage"],
);
}
Map<String, dynamic> toJson() => {
"totalItems": totalItems,
"itemCount": itemCount,
"itemsPerPage": itemsPerPage,
"totalPages": totalPages,
"currentPage": currentPage,
};
}