HomeiOS Developmentandroid - Countdown timer in Flutter Help

android – Countdown timer in Flutter Help


I’m attempting to create an app and show a round countdown timer, nevertheless it solely works for a second earlier than calling a bunch of different totally different operate, and I’m actually confused why that is occurring. Thanks a lot!

Issues I’ve tried

  • Calling a operate that begins the controller – nevertheless this begins the timer for like a second after which stops it

Right here is the button code

GestureDetector(
                                    onTap: () {
                                      currentExerciseIndex ==
                                              widget.workouts.size - 1
                                          ? null
                                          : nextSet();
                                    },
                                    baby: Icon(
                                      Icons.arrow_forward,
                                      colour: currentExerciseIndex ==
                                              widget.workouts.size - 1
                                          ? Colours.gray
                                          : Colours.black,
                                      measurement: measurement.width * .13,
                                    )),

It calls a operate referred to as nextSet(), which does this

  void nextSet() {
    // Add this methodology
    if (currentSetIndex % 2 == 0) {
      // new set is a relaxation set if the index is odd
      print('relaxation');
      timeMap[currentSetIndex] = elapsedTime; //set time for particular set
      print(timeMap);
      elapsedTime = 0;
      isPaused = true;
    }
    if (currentSetIndex <
        (int.parse(widget.workouts[currentExerciseIndex]['sets']) * 2 - 1) -
            1) {
      isPaused = false;
      setState(() {
        currentSetIndex++;
      });
    } else {
      nextExercise();
    }
  }

Listed here are the ultimate two items of knowledge, plus some variables. That is the listview

SingleChildScrollView(
                      scrollDirection: Axis.horizontal,
                      baby: Row(
                        youngsters: Record.generate(
                          int.parse(widget.workouts[currentExerciseIndex]
                                      ['sets']) *
                                  2 -
                              1,
                          (index) {
                            var isCurrentSet = currentSetIndex == index;

                            return Card(
                              colour: isCurrentSet
                                  ? Coloration.fromARGB(255, 224, 224, 224)
                                  : Coloration.fromARGB(255, 66, 66, 66),
                              baby: Container(
                                top: isCurrentSet
                                    ? measurement.top * .15
                                    : measurement.top * .1,
                                width: measurement.width *
                                    0.4, // Modify this as per your requirement
                                baby: Container(
                                    //padding: const EdgeInsets.all(10),
                                    baby: isCurrentSet
                                        ? Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.middle,
                                            youngsters: [
                                              index % 2 == 1
                                                  ? Row(children: [
                                                      SizedBox(width: 8),
                                                      Text('Rest:',
                                                          style: TextStyle(
                                                              fontSize: 20)),
                                                      progress()
                                                    ])
                                                  : Container(
                                                      padding: EdgeInsets.solely(
                                                          high: 10),
                                                      baby: Column(youngsters: [
                                                        Text(
                                                          'Set: ' +
                                                              ((index ~/ 2) + 1)
                                                                  .toString(),
                                                          style: TextStyle(
                                                            fontSize: 20,
                                                            color: Colors.black,
                                                          ),
                                                        ),
                                                        Container(
                                                            height:
                                                                size.height *
                                                                    .07,
                                                            width:
                                                                size.width * .4,
                                                            child: FittedBox(
                                                                child: Text(
                                                                    formatDuration(
                                                                        elapsedTime),
                                                                    style: TextStyle(
                                                                        fontWeight:
                                                                            FontWeight.bold))))
                                                      ]))
                                            ],
                                          )
                                        : index % 2 == 1
                                            ? Middle(
                                                baby: Textual content('Relaxation',
                                                    model: TextStyle(
                                                        colour: Colours.white,
                                                        fontSize: 20)))
                                            : Middle(
                                                baby: Textual content(
                                                    'Set: ' +
                                                        ((index ~/ 2) + 1)
                                                            .toString(),
                                                    model: TextStyle(
                                                        colour: Colours.white,
                                                        fontSize: 20)))),
                              ),
                            );
                          },
                        ),
                      ),
                    ),

And listed here are some remaining variables and features

  late CountDownController controller = CountDownController();

  Widget progress() {
    var measurement = MediaQuery.of(context).measurement;
    //controller.begin();
    return CircularCountDownTimer(
      width: measurement.width * .25,
      top: measurement.top * .1,
      period: 60,
      strokeWidth: 10.0,
      fillColor: Coloration.fromARGB(255, 2, 203, 12),
      ringColor: Coloration.fromARGB(255, 52, 52, 52),
      autoStart: false,
      controller: controller,
      onComplete: () {
        elapsedTime = 0;
        nextExercise();
      },
    );
  }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments