http_result.dart 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import 'package:ftrecruiter/comm/utils/log_utils.dart';
  2. class HttpResult<T> {
  3. HttpResult({required this.isSuccess, dynamic dataJson, List<dynamic>? listJson, this.errorCode, this.errorMsg}) {
  4. this._dataJson = dataJson;
  5. this._listJson = listJson;
  6. }
  7. //是否成功
  8. bool isSuccess = false;
  9. //成功的数据(Json数据)
  10. dynamic _dataJson;
  11. List<dynamic>? _listJson;
  12. //成功的数据(真正的数据)
  13. T? data;
  14. List<T>? list;
  15. //失败的数据
  16. int? errorCode;
  17. String? errorMsg;
  18. Map<String, dynamic>? getDataJson() {
  19. if (_dataJson is Map<String, dynamic>) {
  20. return _dataJson as Map<String, dynamic>;
  21. }
  22. return null;
  23. }
  24. List<dynamic>? getListJson() {
  25. return _listJson;
  26. }
  27. /// 设置真正的数据对象
  28. void setData(T data) {
  29. this.data = data;
  30. }
  31. void setList(List<T> list) {
  32. this.list = list;
  33. }
  34. /// 基本类型转换为指定的泛型类型
  35. HttpResult<T> convert<T>({T? data, List<T>? list}) {
  36. var result = HttpResult<T>(
  37. isSuccess: this.isSuccess,
  38. dataJson: this._dataJson,
  39. listJson: this._listJson,
  40. errorCode: this.errorCode,
  41. errorMsg: this.errorMsg);
  42. result.data = data;
  43. result.list = list;
  44. return result;
  45. }
  46. }