stream_with_value
0.5.0, released 4 years ago by futureware.dev
Encapsulates a Stream<T> with its latest value and load state.
WASM-ready
What it does
It provides an interface that exposes a Stream<T>, the most recent value emitted, and a flag indicating whether a value has been loaded. The package also offers widgets that simplify displaying progress indicators while waiting for the first value.
AI-written summary of version 0.5.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need to access the latest stream value outside of a listen callback
- Want to avoid flickering when rebuilding widgets after a rotation
- Need a simple way to show a loading indicator until a stream emits its first value
Skip it when
- Using multi-subscription streams that require immediate subscription
- When you need to transform or combine streams with complex logic that is better handled by other stream utilities
Strengths
- Easy access to the latest value without manual state management
- Built-in widgets reduce boilerplate for loading states
- Works with any single-subscription Stream
Weaknesses
- Does not automatically subscribe to the stream; the first value is only available after a subscription
- Limited to single-subscription streams
- No built-in support for stream transformations or combinators
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Add dependency to pubspec and import the package; no special permissions or build_runner needed
final counter = StreamWithValue<int>(Stream<int>.periodic(const Duration(seconds: 1)));
// In a widget
StreamBuilderWithValue<int>(
streamWithValue: counter,
builder: (ctx, snapshot) => snapshot.hasData
? Text('${snapshot.data}')
: CircularProgressIndicator(),
);Alternatives
Packages that do the same job and could replace stream_with_value.
- side_effect_bloc
Extended bloc with a separate stream for one-time side effects.
45Compare - async_value_group
Group multiple Riverpod AsyncValues into a single AsyncValue
48Compare