1

I m trying to loop time in minutes and seconds to display them as a list on the widget as shown on the picture below. It might be my math problem that causing this or lack of a better way of achieving this, but I have tried and I m stack.

My problem was on capturing the minutes and seconds, like e.g you have 15minutes. and you want then to be displayed like this. [00:00, 00:30, 1:00, 1:30, 2:00, 2:30,3:00, 3:30....15:00],

So the issue is only achieving that.

here the image

enter image description here

void addTime() {
    const addSeconds = 1;
    setState(() {
int s = 0;
      for(int i = 0; i <= Duration(minutes: 15).inMinutes; i++){

        timelines.add(buildTime(minute:(i * 60) % 1 * 60.floor(),
            sec: i > 0 ? (i * 60).floor() : 0));
      }

    });
  }

So once the app is open then addTime will be called to fill the timelines List[], Then the timelines will be rendered on the build.

Kindly assist in any way possible for me to get this done.

1 Answers1

0

I manage to solve the problem by looping the seconds inside the minutes loop, here the code.

void addTime() {
    setState(() {

      for (int i = 0; i <= 15; i++) {
        for (int j = 0; j < 60; j++) {
          if (j % 30 == 0) {
            String minutes = i.toString().padLeft(2, '0');
            String seconds = j.toString().padLeft(2, '0');
            timelines.add(buildTime(minute: minutes,
                sec: seconds));
          }
        }
      }

    });
  }

enter image description here