Reputation:
I need to know if there are only string equals to "Validated" in the list, how can I check it in 1 line of code ? (If the list is empty, I already checked the condition before so this particular case isn't important).
List<String> state_str_list = ["Validated", "Draft", "Draft", "Waiting", "Validated"];
if (???) {
print("all values in state_str_list are equals to 'Validated' !");
}
Upvotes: 4
Views: 7081
Reputation:
Thanks to you, I came to this:
contains_only(var _list, var e) {
_list.every((element) => element == e);
}
print(contains_only(["Validated", "Draft", "Draft", "Waiting", "Validated"], "Validated"));
Upvotes: 6