Home > OS >  How to loop through two lists at the same time - Flutter
How to loop through two lists at the same time - Flutter

Time:10-22

I'm trying to loop through two lists at the same time

For example

List A = ['Chapter 1','Chapter 2','Chapter 3'];
List B = ['Paragraph 1','Paragraph 2','Paragraph 3'];

for(var chapter in A)  // This would itreate through only first list (A), How can I iterate through both list
children: [
     Text(chapter);   
     Text(paragraph);
]

I need to iterate through both lists at the same time in "for" loop.

CodePudding user response:

Here is the code:

  List A = ['Chapter 1','Chapter 2','Chapter 3'];
  List B = ['Paragraph 1','Paragraph 2','Paragraph 3'];
  for (int i = 0; i < A.length; i  ) {
      print ("${A[i]}");
      print ("${B[i]}");
  }

Let me know if this does not help.

CodePudding user response:

final c = zip([a, b]).map((item) => Foo(item[0], item[1])).toList();
  • Related