here i have String list and String variable which cotwins the wanted letters
List myBooks ['hello world' , 'hello dart', 'hello flutter'] ;
String isBook = 'flutter' // here i target the hello flutter element
here i have Text Widget and String Method
Text(getBook(isBook ))
String getBook(String isBook ){
return // here i need to return the whole length of element that contains 'flutter'
so i need to get 'hello flutter'
}
How to handle this
>Solution :
You can use List.firstWhere to find element and .contains() to check value;
String getBook(String isBook) {
List myBooks = ['hello world', 'hello dart', 'hello flutter'];
return myBooks.firstWhere((b) => b.contains(isBook));
}
void main() {
String isBook = 'flutter';
print(getBook(isBook)); // hello flutter
}