Skip to content

Instantly share code, notes, and snippets.

View MisterJimson's full-sized avatar

Jason Rai MisterJimson

View GitHub Profile
@MisterJimson
MisterJimson / README.md
Last active March 28, 2021 02:54 — forked from GroovinChip/README.md
My "Vintage bloc" usage style

My use of the classic (or "vintage") BLoC pattern (not to be confused with Felix Angelov's great bloc library) has evolved over the years. I do no use dedicated sinks for input and dedicated streams for output. Rather, I directly use rxdart's excellent BehaviorSubject directly. BehaviorSubject implements ValueStream, which itself implements Stream, so I found that I could reduce boilerplate a lot by doing this. Values can be directly added to, and read from, a BehaviorSubject. I then use provider to pass my services (I don't really think of them as "bloc"s any more) through my app. This gist provides a real example of how I currently use this pattern.

  • prefs_service.dart is where the service is defined.
  • main.dart shows how to initialize the service.
  • app.dart shows how I use MultiProvider to pass down my service. I always use MultiProvider rather than one single provider to allow for more services. I listen to the BehaviorSubject in my service to set the ThemeMode of my `Ma