Skip to content

Instantly share code, notes, and snippets.

@tafaust
Created February 6, 2021 07:06
Show Gist options
  • Save tafaust/1f242ccd1bbb917c3a338b17ca2c14e9 to your computer and use it in GitHub Desktop.
Save tafaust/1f242ccd1bbb917c3a338b17ca2c14e9 to your computer and use it in GitHub Desktop.
How to check if Dart List contains certain object instance?
class Book {
String title;
Book(this.title);
}
void main() {
List<Book> bookList = [
Book('foo'),
];
if (bookList is Book) {
print("A");
} else if (bookList.contains(Book)) {
print("B");
} else {
print("C");
}
}
@tafaust
Copy link
Author

tafaust commented Feb 6, 2021

Showcase for https://stackoverflow.com/a/66074291/2402281 that his/her code doesn't work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment