0
  Future<dynamic> refreshState() async {
    setState(() {});
    await Future<dynamic>.delayed(animDuration + const Duration(milliseconds: 50));
    if (isPlaying) {
      await refreshState();
    }
  }

currently refreshState() is running non-stop. I want refreshState to run for 1 sec, then stop. I assume I need to set isPlaying = !isPlaying at some point but where?

Thanks!

sea
  • 43
  • 4

1 Answers1

0

You need to add a count down parameter:

Future<dynamic> refreshState(int timeLeft) async {
    setState(() {});
    await Future<dynamic>.delayed(animDuration + const Duration(milliseconds: 50));
    if (isPlaying && timeLeft>0) {
      await refreshState(timeLeft-50);
    }
  }

....
refreshState(1000);
....
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210