I am creating a wishlist true false functionality. In _favListData List variable I have data but in this variable my data is different
This is my _favListData List data, in this data i have two object but different type.
[
{
uuid: beadecf3-7f43-4086-8645-669f418d60e2,
customerId: 18d74dc1-4254-4b0b-a434-32504b6d42b3,
productId: 12944,
name: HealthTablets,
regular_price: 10,
sale_price: 9,
category: [
{
id: 16,
name: AllProducts,
slug: allproducts
},
{
id: 57,
name: Behavioral,
slug: behavioral
}
],
image: [
{
id: 12934,
date_created: 2022-08-19T09: 40: 30,
date_created_gmt: 2022-08-19T09: 40: 30,
date_modified: 2022-08-19T09: 40: 30,
date_modified_gmt: 2022-08-19T09: 40: 30,
src: https: //mycwc.org/wp-content/uploads/2022/08/10.jpg,
name: 10,
alt:
},
{
id: 12936,
date_created: 2022-08-19T09: 41: 19,
date_created_gmt: 2022-08-19T09: 41: 19,
date_modified: 2022-08-19T09: 41: 19,
date_modified_gmt: 2022-08-19T09: 41: 19,
src: https: //mycwc.org/wp-content/uploads/2022/08/4.jpg,
name: 4,
alt:
},
{
id: 12934,
date_created: 2022-08-19T09: 40: 30,
date_created_gmt: 2022-08-19T09: 40: 30,
date_modified: 2022-08-19T09: 40: 30,
date_modified_gmt: 2022-08-19T09: 40: 30,
src: https: //mycwc.org/wp-content/uploads/2022/08/10.jpg,
name: 10,
alt:
},
{
id: 12933,
date_created: 2022-08-19T09: 39: 37,
date_created_gmt: 2022-08-19T09: 39: 37,
date_modified: 2022-08-19T09: 39: 37,
date_modified_gmt: 2022-08-19T09: 39: 37,
src: https: //mycwc.org/wp-content/uploads/2022/08/6.jpg,
name: 6,
alt:
}
]
},
{
quantity: 1,
inWishlist: true,
_id: 6318b77818f512454aa5bc84,
productId: 12942,
categoryId: 16,
uuid: a2b6736b-1f9c-4a2a-84d2-4271ca69e2b5,
customerId: 18d74dc1-4254-4b0b-a434-32504b6d42b3,
createdAt: 2022-09-07T15: 23: 36.121Z,
updatedAt: 2022-09-07T15: 23: 36.121Z,
__v: 0
}
]
so from _favListData List variable I want to check productId and from another list variable Id is matching or not . I am using this functionalty.
int isExistFav(dynamic data) {
final isExist=
_favListData.indexWhere((element) => element["productId"] == data["id"]);
return isExist;
}
Note: when in _favListData List i have same type of object then is working fine. like this--> Here these data is different id but type is same(key)
[
{
uuid: beadecf3-7f43-4086-8645-669f418d60e2,
customerId: 18d74dc1-4254-4b0b-a434-32504b6d42b3,
productId: 12944,
name: HealthTablets,
regular_price: 10,
sale_price: 9,
category: [
{
id: 16,
name: AllProducts,
slug: allproducts
},
{
id: 57,
name: Behavioral,
slug: behavioral
}
],
image: [
{
id: 12934,
date_created: 2022-08-19T09: 40: 30,
date_created_gmt: 2022-08-19T09: 40: 30,
date_modified: 2022-08-19T09: 40: 30,
date_modified_gmt: 2022-08-19T09: 40: 30,
src: https: //mycwc.org/wp-content/uploads/2022/08/10.jpg,
name: 10,
alt:
},
{
id: 12936,
date_created: 2022-08-19T09: 41: 19,
date_created_gmt: 2022-08-19T09: 41: 19,
date_modified: 2022-08-19T09: 41: 19,
date_modified_gmt: 2022-08-19T09: 41: 19,
src: https: //mycwc.org/wp-content/uploads/2022/08/4.jpg,
name: 4,
alt:
},
{
id: 12934,
date_created: 2022-08-19T09: 40: 30,
date_created_gmt: 2022-08-19T09: 40: 30,
date_modified: 2022-08-19T09: 40: 30,
date_modified_gmt: 2022-08-19T09: 40: 30,
src: https: //mycwc.org/wp-content/uploads/2022/08/10.jpg,
name: 10,
alt:
},
{
id: 12933,
date_created: 2022-08-19T09: 39: 37,
date_created_gmt: 2022-08-19T09: 39: 37,
date_modified: 2022-08-19T09: 39: 37,
date_modified_gmt: 2022-08-19T09: 39: 37,
src: https: //mycwc.org/wp-content/uploads/2022/08/6.jpg,
name: 6,
alt:
}
]
},
{
"uuid": "e923567d-272c-421b-85c4-c29d9e23cc7c",
"customerId": "18d74dc1-4254-4b0b-a434-32504b6d42b3",
"productId": 12944,
name: Cancer,
regular_price: 10,
sale_price: 9,
category: [
{
id: 16,
name: AllProducts,
slug: allproducts
},
{
id: 57,
name: Behavioral,
slug: behavioral
}
],
image: [
{
id: 12934,
date_created: 2022-08-19T09: 40: 30,
date_created_gmt: 2022-08-19T09: 40: 30,
date_modified: 2022-08-19T09: 40: 30,
date_modified_gmt: 2022-08-19T09: 40: 30,
src: https: //mycwc.org/wp-content/uploads/2022/08/10.jpg,
name: 10,
alt:
},
{
id: 12936,
date_created: 2022-08-19T09: 41: 19,
date_created_gmt: 2022-08-19T09: 41: 19,
date_modified: 2022-08-19T09: 41: 19,
date_modified_gmt: 2022-08-19T09: 41: 19,
src: https: //mycwc.org/wp-content/uploads/2022/08/4.jpg,
name: 4,
alt:
},
{
id: 12934,
date_created: 2022-08-19T09: 40: 30,
date_created_gmt: 2022-08-19T09: 40: 30,
date_modified: 2022-08-19T09: 40: 30,
date_modified_gmt: 2022-08-19T09: 40: 30,
src: https: //mycwc.org/wp-content/uploads/2022/08/10.jpg,
name: 10,
alt:
},
{
id: 12933,
date_created: 2022-08-19T09: 39: 37,
date_created_gmt: 2022-08-19T09: 39: 37,
date_modified: 2022-08-19T09: 39: 37,
date_modified_gmt: 2022-08-19T09: 39: 37,
src: https: //mycwc.org/wp-content/uploads/2022/08/6.jpg,
name: 6,
alt:
}
]
},
]