Solution: Build a Stopwatch Using RxDart
View the solution of the stopwatch exercise built with RxDart.
Let’s look at a possible solution to the stopwatch project using RxDart.
Creating the StopwatchBloc
The first step is to create the logic of the StopwatchBloc.
Starting the stopwatch
To start the stopwatch, you have to:
Start a timer that calls the
tick()function every second.Update the
isRunningstream that the UI is listening to reflect that the stopwatch is now running.
Press + to interact
void start() {_timer = Timer.periodic(const Duration(seconds: 1), (_) => tick());_isRunning.add(true);}
Pausin
... Ask