'I try to load data from rest API I face the message from catch type 'Null' is not a subtype of type 'Map<String, dynamic>'

i face some errors on my code i cant figure it out, i have tried many step but its stay still, the data i call in provider is working but its still null in the page this is the code.Is there any way to know which field return null here is my model.

  OrderListResponse orderListResponseFromJson(String str) =>
    OrderListResponse.fromJson(json.decode(str));

class OrderListResponse {
  OrderListResponse({
    this.status,
    this.data,
 });

 String? status;
 Data? data;

factory OrderListResponse.fromJson(Map<String, dynamic> json) =>
  OrderListResponse(
    status: json["status"],
    data: Data.fromJson(json["data"]),
  );

}

class Data {
Data({
this.records,
required this.items,
this.pages,
this.page,
});

int? records;
List<OrderItemList> items;
int? pages;
int? page;

factory Data.fromJson(Map<String, dynamic> json) => Data(
    records: json["records"],
    items: List<OrderItemList>.from(json["items"]
        .map<OrderItemList>((items) => OrderItemList.fromJson(items))),
    pages: json["pages"],
    page: json["page"],
  );
}

class OrderItemList {
 OrderItemList({
 this.id,
 this.orderNumber,
 this.total,
 this.status,
 this.type,
 this.storeId,
 this.shortDescription,
 this.orderRating,
 this.createdAt,
 this.cico,
 this.storeLogoUrl,
});

int? id;
String? orderNumber;
double? total;
Status? status;
Type? type;
int? storeId;
String? shortDescription;
int? orderRating;
DateTime? createdAt;
Cico? cico;
String? storeLogoUrl;

factory OrderItemList.fromJson(Map<String, dynamic> json) => OrderItemList(
    id: json["id"],
    orderNumber: json["orderNumber"],
    total: json["total"].toDouble(),
    status: statusValues.map[json["status"]],
    type: typeValues.map[json["type"]],
    storeId: json["storeId"] == null ? null : json["storeId"],
    shortDescription:
        json["shortDescription"] == null ? null : json["shortDescription"],
    orderRating: json["orderRating"],
    createdAt: DateTime.parse(json["createdAt"]),
    cico: json["cico"] == null ? null : Cico.fromJson(json["cico"]),
    storeLogoUrl:
        json["storeLogoUrl"] == null ? null : json["storeLogoUrl"],
  );

}

class Cico {
 Cico({
 this.type,
 this.currency,
 this.amount,
 this.total,
 });

 String? type;
 String? currency;
 int? amount;
 int? total;

factory Cico.fromJson(Map<String, dynamic> json) => Cico(
    type: json["type"] == null ? null : json["type"],
    currency: json["currency"] == null ? null : json["currency"],
    amount: json["amount"] == null ? null : json["amount"],
    total: json["total"] == null ? null : json["total"],
  );
 }

enum Status { processing, completed, canceled }

final statusValues = EnumValues({
"canceled": Status.canceled,
"completed": Status.completed,
"processing": Status.processing
});

enum Type { delivery }

final typeValues = EnumValues({"delivery": Type.delivery});

class EnumValues<T> {
  Map<String, T> map;
  Map<T, String>? reverseMap;

  EnumValues(this.map);

  Map<T, String> get reverse {
 reverseMap ??= map.map((k, v) => MapEntry(v, k));
 return reverseMap!;
 }

}

And there is my provider I perpare for data from rest api:

class OrderListProvider {
 HttpHelper httpHelper = HttpHelper()..init(domain: BaseUrlDomain.wingMall);
 Future<List<OrderListResponse>?> getOrderList({required int page}) async {
 try {
  final response =
      await httpHelper.get(EndPoint.orderList, queryParam: {"page": page});
  if (response.statusCode == 200) {
    var res = response.data['data']['items'] as List;
    log("Information response data: $res");
    return res
        .map<OrderListResponse>(
            (element) => OrderListResponse.fromJson(element))
        .toList();
  }
   return null;
  } catch (error) {
  log("Information error: $error");
  rethrow;
 }
}

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source