stream_mixin
3.0.4, released 5 years ago by dart.nonstopio.com
StreamMixin provides a lightweight stream‑based state manager for Flutter widgets.
What it does
It lets you expose a stream of state changes from a plain Dart class and consume it with StreamBuilder. The mixin handles the stream controller and exposes the last value via lastUpdate.
AI-written summary of version 3.0.4, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a simple, performance‑friendly state solution without boilerplate.
- You want to avoid using StatefulWidget and setState for small to medium widgets.
- You prefer a single source of truth that can be shared globally or as a singleton.
Skip it when
- Your app requires complex navigation, dependency injection, or advanced state patterns like BLoC or Redux.
- You need persistence, offline support, or integration with other state libraries.
- You are building a large, feature‑rich app that needs more structure.
Strengths
- No extra dependencies beyond Flutter.
- Easy to use with a single line mixin and StreamBuilder.
- Provides lastUpdate for quick access to the current value.
- Performance gains by avoiding rebuilds of the whole widget tree.
Weaknesses
- Limited to stream‑based state; no built‑in persistence or routing.
- No built‑in testing utilities beyond basic unit tests.
- Lacks advanced features like selectors or middleware.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
class Counter with StreamMixin<int>{
void increment(){
update((lastUpdate ?? 0)+1);
}
}
final counter=Counter();
Widget build(BuildContext ctx)=>StreamBuilder<int>(
stream: counter.onChange,
builder:(cxt,snap)=>Text((snap.data ?? 0).toString()),
);Alternatives
Packages that do the same job and could replace stream_mixin.
- yx_state
A state management library for Dart and Flutter applications.
82Compare - riverpod
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
99Compare - bloc_tools
Command-line tools for generating and linting bloc and cubit components.
88Compare - cached_query
Library for caching, background fetching, and managing server state in Dart and Flutter.
90Compare
Works with
Packages commonly used together with stream_mixin: ones it builds on, ones built on it, and its own family.