toJson method

  1. @override
Map<String, dynamic> toJson()
override

Converts the QueryModel to a JSON object.

This method can be used when making HTTP requests to convert the query model to a format that can be sent in the request. It only includes the page and amount properties if they are not null.

Implementation

@override
Map<String, dynamic> toJson() {
  Map<String, dynamic> data = super.toJson();
  if (type != null) data["type"] = type.toString().split('.').last;
  if (stockType != null) {
    if (stockType == StockStatus.stock_in) {
      data["stockType"] = "in";
    } else {
      data["stockType"] = stockType.toString().split('.').last;
    }
  }
  if (stockStatus != null) {
    data["stockStatus"] = stockStatus.toString().split('.').last;
  }
  if (storeId != null) data["storeId"] = storeId;
  if (productId != null) data["productId"] = productId;
  return data;
}