ResponseItemDTO<T> constructor

ResponseItemDTO<T>({
  1. required ResponseModel response,
  2. dynamic fromJson(
    1. Map<String, dynamic>
    )?,
  3. bool isSingleData = false,
})

Creates a new instance of ResponseItemDTO.

The response parameter is used to initialize the response item. The fromJson parameter is used to convert the item from a JSON object. The isSingleData parameter is used to specify whether the response data is a single item or a list of items.

Implementation

ResponseItemDTO({
  required ResponseModel response,
  this.fromJson,
  bool isSingleData = false,
}) {
  _message = response.message;
  _status = response.statusCode;

  if (response.statusCode! >= 400) {
    _hasError = true;
    _error = response.data ?? response.message;
    if (response.required != null && response.required!.isNotEmpty) {
      _required = response.required;
    }
    return;
  }
  if (response.data == null) {
    return;
  }

  if (isSingleData) {
    item = response.data;
  } else {
    if (fromJson != null) {
      item = fromJson!(response.data);
    }
  }
}