felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.83k stars 3.4k forks source link

How to implement a countdown timer using bloc? #307

Closed schatekar closed 5 years ago

schatekar commented 5 years ago

I need to show a countdown timer on a screen. Since I am using bloc elsewhere in the App, I thought it could be good idea to use bloc to update the watch display in the presentation layer using a bloc. Has anyone done this before? Some specific questions I have are

  1. How do I dispatch an event on every tick of the clock? I need it down to a second level.
  2. Will it be too much for a bloc to process?
  3. What kind of delay should I expect in the actual display of the timer in the presentation layer due to added processing in the bloc? I am talking about granularity down to a second. If the bloc takes even 100ms to process, there is going to be 10% error which is huge. In that case, it would be good to be able to adjust the lag, say, every 10th second or so.
felangel commented 5 years ago

Hi @schatekar 👋 Thanks for opening an issue and great question!

I will put together a flutter_timer example over the next few days to address your questions 👍

felangel commented 5 years ago

@schatekar check out examples/flutter_timer 👍