Created
February 6, 2021 07:06
-
-
Save tafaust/1f242ccd1bbb917c3a338b17ca2c14e9 to your computer and use it in GitHub Desktop.
How to check if Dart List contains certain object instance?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Showcase for https://stackoverflow.com/a/66074291/2402281 that his/her code doesn't work as expected.