Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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.

like image 975
shakky Avatar asked Mar 06 '26 16:03

shakky


1 Answers

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.

like image 88
Canada2000 Avatar answered Mar 08 '26 13:03

Canada2000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!