Home > Back-end >  type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Client
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Client

Time:05-24

I want to get the Client name from the Api using fromMap() method as shown bellow:

factory Order.fromMap(Map<String, dynamic> map) {
  return Order(
   created_at: Tracker.decode(map['created_at']),
   id: map['id'],
   updated_at: Tracker.decode(map['updated_at']),
   total_price: map['total_price'],
   status: map['status'],
   client: map['client']


  );
 }

client is an object of Client Model .. I got the following error:
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Client' in type cast...

thank you for your help!

CodePudding user response:

You are trying to assign a data of type Map<String, dynamic> to the client which seems to the of type Client.

You need to convert the map['client'] into the Client by using Client.fromMap(map['client']) assuming you have the Client model

  • Related