booked_utils 1.0.0
booked_utils: ^1.0.0 copied to clipboard
A collection of reusable Flutter utilities: typedefs, wrappers, extensions, and helpers for rapid development across multiple projects.
booked_utils #
A set of practical utilities for building Flutter apps faster: typed builders, wrappers for common patterns (ValueNotifier, StreamController), stream extensions, and chunked transformations.
Features #
- Typed Widget Builders (
CallbackWidgetBuilder) - Reactive Wrappers for
ValueNotifierandStreamController - Stream Extensions (e.g., doOnFirst)
- Chunked List Stream Transformer
All utilities are designed to be minimal, composable, and suitable for clean-architecture Flutter codebases.
Installation #
Add to your pubspec.yaml:
dependencies:
booked_utils: ^<latest_version>
Import in your Dart files:
import 'package:booked_utils/booked_utils.dart';
Contents #
1. CallbackWidgetBuilder<T> #
typedef CallbackWidgetBuilder<T> = Widget Function(T value);
A generic typedef for widget builders that take a value of type T.
2. ValueNotifierWrapper<T> #
ValueNotifierWrapper<int>(
initialValue: 0,
onChange: (value) => print('Value changed: $value'),
child: (notifier) => ValueListenableBuilder<int>(
valueListenable: notifier,
builder: (context, value, _) => Text('Value: $value'),
),
)
Wraps a ValueNotifier for local, reactive state. Automatically disposes the notifier and can notify about changes.
3. StreamControllerWrapper<T> #
StreamControllerWrapper<String>(
child: (controller) => StreamBuilder<String>(
stream: controller.stream,
builder: (context, snapshot) => Text(snapshot.data ?? ''),
),
)
Manages the lifecycle of a StreamController and exposes it to a widget subtree.
4. ChunkTransformer<T> #
final chunkedStream = Stream.value(List.generate(10000, (i) => i))
.transform(const ChunkTransformer<int>(chunkSize: 1024));
await for (final chunk in chunkedStream) {
print('Chunk size: ${chunk.length}');
}
A StreamTransformer that splits large incoming lists into fixed-size chunks. Useful for chunked uploads, network transfers, or file operations.
5. DoOnFirstEvent<T> Extension #
Stream<int>.fromIterable([1, 2, 3])
.doOnFirst((first) async => print('First event: $first'))
.listen(print); // Prints: First event: 1, then 1, 2, 3
Allows performing an action (sync or async) on the first event of a stream, for initialization or logging.
Why use booked_utils? #
- Reduces boilerplate: No need to manually manage controllers or notifiers for simple scenarios.
- Composable patterns: Designed for local state and micro-architecture without global dependencies.
- Production-ready: Null-safe, thoroughly tested in real Flutter apps.
API Reference #
Each class and extension is documented with code samples in the source. See
ValueNotifierWrapperStreamControllerWrapperChunkTransformerDoOnFirstEventCallbackWidgetBuilder
License #
MIT