Streaming String from Firebase and Convert it to timer data in flutter

So the problem I have is I’m importing a String from Firebase and convert it to a timeComponent and the String is right it gets displayed right as a String in the stopwatch but if I start the stopwatch it resets the String to 0 and counts upwards from 0 again but I want it to keep counting from the imported String since this is the “edit” window from an already started task.


void stoppedtimedisplay() async {
    String timeDocID = await _getDocID();
    setState(() {
      timeComponents = timeDocID.split(':');
      int hours = int.parse(timeComponents[0]);
      int minutes = int.parse(timeComponents[1]);
      int seconds = int.parse(timeComponents[2]);
      firebaseDuration =
          Duration(hours: hours, minutes: minutes, seconds: seconds);
    });

so that’s the function im calling to get the time components

and im calling this function inside of the super init state

 void initState() {
    super.initState();
    stoptimetodisplay = "Loading...";
    stoppedtimedisplay();
  }

and then I add this firebaseDuration to my stopwatch

  void startstopwatch() {
    setState(() {
      stopispressed = false;
      startispressed = false;
      resetispressed = true;
    });
    swatch.start();
    swatch.elapsed + firebaseDuration;
    starttimer();
  }

but it starts from 0. Am I using the wrong math? or what is my error here? 🙂 I’m new to coding but I would appreciate help 😀

Leave a Comment