Amir
Amir

Reputation: 65

type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Client' in type cast in flutter?

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!

Upvotes: 0

Views: 38

Answers (1)

Sujan Gainju
Sujan Gainju

Reputation: 4769

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

Upvotes: 2

Related Questions