1

I have searched a lot. But couldn't get what I am looking for.

I have a list with inner lists as its objects

final posts = [ ["My First Post, "myPostId"], ["My SecondPost, "myPostId2"]..... ];

So, I want to check if the list contains the word First. It is working with 1D lists like

posts = ["My First Post", "My Second Post"];
posts.where((p)=>p.contain("First")....

//gives the correct result

But what's the way to get from the inner lists.

Actual Code

final suggestion = query.isEmpty?courseNameList:courseNameList
.where((test)=>test.contains(query.toLowerCase())).toList();

Thanks in advance!

1
  • you can create a other one dimension list and search from it and then base on index display data whatever you want to show. Commented May 7, 2020 at 7:53

2 Answers 2

2

Hello check this solution if it is ok:

final posts = [ 
  ["My First Post", "myPostId"], 
  ["My SecondPost", "myPostId2"],
];

void main() {
  List suggestions = List();
  posts.forEach((postList){
    if(postList[0].contains("First")) 
      suggestions.add(postList);

  });

  suggestions.forEach((sugg)=>print("Found ID: ${sugg[1]}"));
}
Sign up to request clarification or add additional context in comments.

2 Comments

final suggestion = query.isEmpty?courseNameList:courseNameListLower .where((test)=>test.contains(query.toLowerCase())).toList(); This is my actual code. I need to assign those results into list (suggestion), instead .
@FathahKodag I have modified my answer to return a List; hope it helps!
1
void main() {
  final result = posts.any((e) => e.any((e) => e.contains('First')));
  print(result);
}

final posts = [
  ["My First Post", "myPostId"],
  ["My SecondPost", "myPostId2"]
];

5 Comments

I need to assign those results to another list. As any() is a bool I cannot get the result, instead, it returns true/false
Please check the question. I have added some more code.
This was the answer to your main question Check if inner lists contain some string value in Flutter. Documentation: api.dart.dev/stable/2.8.1/dart-core/Iterable/any.html Checks whether any element of this iterable satisfies test.. What exactly does not suit you?
Ask a new question on StackOverflow. what's the way to get from the inner lists.
Tnx for trying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.