HomeiOS Developmentandroid - Coundown Timer in Flutter

android – Coundown Timer in Flutter


So I’m making an attempt to make a exercise app and show a round countdown timer. This timer must be reusuable, and in addition must look good. I’ve this button that calls a perform, that shows the round countdown timer. Thanks a lot!!!

Issues I’ve tried

  • Calling a perform that begins the controller – nevertheless this begins the timer for like a second after which stops it
  • Thats actually it lol – nothing else labored

Right here is the button code

GestureDetector(
                                    onTap: () {
                                      currentExerciseIndex ==
                                              widget.workout routines.size - 1
                                          ? null
                                          : nextSet();
                                    },
                                    youngster: Icon(
                                      Icons.arrow_forward,
                                      coloration: currentExerciseIndex ==
                                              widget.workout routines.size - 1
                                          ? Colours.gray
                                          : Colours.black,
                                      dimension: dimension.width * .13,
                                    )),

It calls a perform 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.workout routines[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,
                      youngster: Row(
                        kids: Listing.generate(
                          int.parse(widget.workout routines[currentExerciseIndex]
                                      ['sets']) *
                                  2 -
                              1,
                          (index) {
                            var isCurrentSet = currentSetIndex == index;

                            return Card(
                              coloration: isCurrentSet
                                  ? Colour.fromARGB(255, 224, 224, 224)
                                  : Colour.fromARGB(255, 66, 66, 66),
                              youngster: Container(
                                top: isCurrentSet
                                    ? dimension.top * .15
                                    : dimension.top * .1,
                                width: dimension.width *
                                    0.4, // Modify this as per your requirement
                                youngster: Container(
                                    //padding: const EdgeInsets.all(10),
                                    youngster: isCurrentSet
                                        ? Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.heart,
                                            kids: [
                                              index % 2 == 1
                                                  ? Row(children: [
                                                      SizedBox(width: 8),
                                                      Text('Rest:',
                                                          style: TextStyle(
                                                              fontSize: 20)),
                                                      progress()
                                                    ])
                                                  : Container(
                                                      padding: EdgeInsets.solely(
                                                          prime: 10),
                                                      youngster: Column(kids: [
                                                        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
                                            ? Heart(
                                                youngster: Textual content('Relaxation',
                                                    fashion: TextStyle(
                                                        coloration: Colours.white,
                                                        fontSize: 20)))
                                            : Heart(
                                                youngster: Textual content(
                                                    'Set: ' +
                                                        ((index ~/ 2) + 1)
                                                            .toString(),
                                                    fashion: TextStyle(
                                                        coloration: Colours.white,
                                                        fontSize: 20)))),
                              ),
                            );
                          },
                        ),
                      ),
                    ),

And listed below are some ultimate variables and capabilities

  late CountDownController controller = CountDownController();

  Widget progress() {
    var dimension = MediaQuery.of(context).dimension;
    //controller.begin();
    return CircularCountDownTimer(
      width: dimension.width * .25,
      top: dimension.top * .1,
      period: 60,
      strokeWidth: 10.0,
      fillColor: Colour.fromARGB(255, 2, 203, 12),
      ringColor: Colour.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