Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter how to loop through multiple lists

I am using this code to loop through a list in flutter:

if (notificationDays.isNotEmpty) {
          for (var i = 0; i < selectedNotificationDays.length; i++) {
            createWaterReminderNotification(
                'Reminder',
                NotificationWeekAndTime(
                    dayOfTheWeek: int.parse(selectedNotificationDays[i]),
                    timeOfDay: remindertime));
          }
        }

But now I want to replace ‘remindertime’ with a list instead.
What can I do to loop through every item in this list?
I have tried this but it doesn’t work:

if (notificationDays.isNotEmpty) {
          for (var i = 0; i < selectedNotificationDays.length; i++) {
            createWaterReminderNotification(
                'Reminder',
                NotificationWeekAndTime(
                    dayOfTheWeek: int.parse(selectedNotificationDays[i]),
                    timeOfDay: remindertime[i]));
          }
        }

‘remindertime’ is now a list of multiple ‘timeOfDay’.
So, I got one list with days called ‘selectedNotificationDays’. and one list with times called ‘remindertime’.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want to create a reminder on every day of selectedNotificationDays. and on that day I want to create this reminder on every time of reminder time.

like this:
Monday: (10.00 12.30 15.00)
Tuesday: (10.00 12.30 15.00)
Friday: (10.00 12.30 15.00)

>Solution :

You would need to use another for loop. I also recommend replacing it with a for in for better readability. This is how you do it:

for(var selectedDay in selectedNotificationDays){
  for(var reminder in remindertime){
    createWaterReminderNotification(
      'Reminder',
      NotificationWeekAndTime(
        dayOfTheWeek: int.parse(selectedDay),
        timeOfDay: reminder,
      ),
    );
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading