import 'package:sport/bean/page.dart'; import '../Converter.dart'; class Resp { int code = -1; String msg; Resp(this.code, this.msg); factory Resp.fromJson(Map json) { return Resp(json['code'], json['msg'] ?? ""); } } class RespData extends Resp { T? data; RespData(code, msg, this.data) : super(code, msg); factory RespData.fromJson(Map json) { return RespData(json['code'], json['msg'], json['data'] != null ? Converter.fromJson(json['data']) : null); } } class RespList extends Resp { List results; RespList(code, msg, this.results) : super(code, msg); factory RespList.fromJson(Map json) { List results = []; if (json['data'] != null) { (json['data'] as List).forEach((element) { var item = Converter.fromJson(element); if (item != null) results.add(item); }); } return RespList(json['code'], json['msg'], results); } } class PageResult { List? results; Page? page; int count; PageResult({this.results, this.page, this.count = 0}); } class RespPage extends Resp { PageResult pageResult; RespPage(code, msg, this.pageResult) : super(code, msg); factory RespPage.fromJson(Map json) { PageResult pageResult = PageResult(); List results = []; if (json['data'] != null) { Map data = json['data']; if (data['list'] != null) { (data['list'] as List).forEach((element) { var item = Converter.fromJson(element); if (item != null) results.add(item); }); pageResult.results = results; } else if (data['data'] != null) { (data['data'] as List).forEach((element) { var item = Converter.fromJson(element); if (item != null) results.add(item); }); pageResult.results = results; } Page page = Page(); if (data['pages'] != null) { page = Page.fromJson(data['pages'] as Map); pageResult.page = page; } if (data['count'] != null) { pageResult.count = Converter.toInt(data['count']); } } return RespPage(json['code'], json['msg'], pageResult); } }