1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import 'package:ftrecruiter/comm/utils/log_utils.dart';
- class HttpResult<T> {
- HttpResult({required this.isSuccess, dynamic dataJson, List<dynamic>? listJson, this.errorCode, this.errorMsg}) {
- this._dataJson = dataJson;
- this._listJson = listJson;
- }
- //是否成功
- bool isSuccess = false;
- //成功的数据(Json数据)
- dynamic _dataJson;
- List<dynamic>? _listJson;
- //成功的数据(真正的数据)
- T? data;
- List<T>? list;
- //失败的数据
- int? errorCode;
- String? errorMsg;
- Map<String, dynamic>? getDataJson() {
- if (_dataJson is Map<String, dynamic>) {
- return _dataJson as Map<String, dynamic>;
- }
- return null;
- }
- List<dynamic>? getListJson() {
- return _listJson;
- }
- /// 设置真正的数据对象
- void setData(T data) {
- this.data = data;
- }
- void setList(List<T> list) {
- this.list = list;
- }
- /// 基本类型转换为指定的泛型类型
- HttpResult<T> convert<T>({T? data, List<T>? list}) {
- var result = HttpResult<T>(
- isSuccess: this.isSuccess,
- dataJson: this._dataJson,
- listJson: this._listJson,
- errorCode: this.errorCode,
- errorMsg: this.errorMsg);
- result.data = data;
- result.list = list;
- return result;
- }
- }
|