'How to use contains with a list in dart

Hi i have list of objects and i would like to check if a certain object is in the list i have the following code

List<GladiatorOutput> gladiators = await Obstructionum.utDifficultas(principalisDirectory);
for (GladiatorOutput gladiator in gladiators) {
  print(gladiator.toJson());
}
print(gladiatorToAttack.outputs[conf.index].toJson());
if (!gladiators.contains(gladiatorToAttack.outputs[conf.index])) {
  return Response.forbidden(json.encode({
    "code": 0,
    "message": "Gladiator non inveni",
    "english": "Gladiator not found"
  }));
}

with the following output

{rationem: [{probationem: d24bb59f1b6d86fd0c6bb860faa204eb377289e9ad8ec4096a789fbf1bcf2ddf, interioreRationem: {publicaClavis: 043af38cfb7ff7cd65d73fe926cd3547aa143ab0041479ec19933a5732f3ad40aeb361b2ff64fa4d5ed79daefc569497c6d0c83cbc8748b6bbb51cbe2b5c264b30, nonce: 0, id: 6834a99b8b1880eaaf6eea1bf6d3475e3bc3b54de9c3b750a257a8b47fbbcf64}}], defensio: 6a}
{rationem: [{probationem: 0000eb7896fe02966d5690cfb5838d638f3b2e6761ea00bd09d735ba0911d58a, interioreRationem: {publicaClavis: 04282a6a6dbc6f3a255786db2ab4521f3b592a910262771b47d9b2847839413a9191c72c5dd8a7a3f4b7972c502062d600171464ee4c4db322966a5f3af089b02d, nonce: 155531, id: fcf1c5dac4d40b61b7e20ca078940d7d925e21f618ecdad300a45afba9a5d2b3}}], defensio: e8}
{rationem: [{probationem: 0000b7de2cf7b2e3c1c1849991d9ce3717c3cb536d42bac4fa7e603bd7c13231, interioreRationem: {publicaClavis: 049da1bcf3374b7aa543bc135134fd6cff416658447517a448b3cc929ce94fc151e6f3bde849d317b30484a03288cc48e92cdd168ff99838dfab900c32f3ff20d2, nonce: 65750, id: 3ebcb052e32663d89275591fd13dfffd33041b77aa216715d8f0cf96af968368}}], defensio: ef}
{rationem: [], defensio: cf}
{rationem: [], defensio: 75}
{rationem: [], defensio: 8e}
{rationem: [], defensio: b4}
{rationem: [], defensio: b4}

could someone tell me why contains is not giving true



Solution 1:[1]

it's hard to tell without knowing the contents of gladiators, maybe print gladiators, and see if gladiatorToAttack.outputs[conf.index] is there, however also, your question says you would like to check "if the object is in the list", but !gladiators.contains(gladiatorToAttack.outputs[conf.index]) you're asking it in the code to check "if the object is NOT in the list", clarify please what exactly you wanna do

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 public static void main