Why do both of the results print the same?
final list1 = [ "a", "b", "c" ];
final result1 = true ? list1 : list1..removeWhere((e) => e == "a");
print(result1); // prints ["b", "c"]
final list2 = [ "a", "b", "c" ];
final result2 = false ? list2 : list2..removeWhere((e) => e == "a");
print(result2); // prints ["b", "c"]
This happens only in ternary condition. When in normal if-else this works just fine.
>Solution :
The ternary operator is evaluated before the cascade operator, so basically the code is equivalent to
final result1 = (true ? list1 : list1)..removeWhere((e) => e == "a");
rather than what you might have expected
final result1 = true ? list1 : (list1..removeWhere((e) => e == "a"));
See: Operator precedence