stream_value 0.0.6 copy "stream_value: ^0.0.6" to clipboard
stream_value: ^0.0.6 copied to clipboard

a simple and lightweight state management solution for Flutter that wraps `StreamController` and `StreamBuilder` to eliminate boilerplate.

πŸš€ Stream Value #

Pub Version License: MIT Platform Build

Stream Value is a simple and lightweight state management solution for Flutter that wraps StreamController and StreamBuilder to eliminate boilerplate.

Unlike other packages, stream_value is focused purely on state. It does not include dependency injectionβ€”staying true to the single responsibility principle.


✨ Features #

  • βœ… Minimal Boilerplate β€” Use streams with ease
  • 🎯 Focused State Management β€” No DI, just state
  • ⚑ Lightweight & Simple β€” Easy to learn and integrate
  • πŸ›‘οΈ Null-Safety by Default β€” Handles nullable & non-nullable types
  • 🧩 Built-in Error Handling β€” Show error widgets with ease

πŸ›  Getting Started #

πŸ“¦ Installation #

Add to your pubspec.yaml:

dependencies:
  stream_value: ^0.0.5  # Check for the latest version

Then run:

flutter pub get

πŸ’‘ Usage #

The package provides two main classes:

StreamValue

StreamValueBuilder

βœ… 1. Create a StreamValue #

final nameStream = StreamValue<String?>(); // Nullable
final counterStream = StreamValue<int>(defaultValue: 0); // Non-nullable

πŸ”„ 2. Update the Value #

void updateName(String newName) {
  nameStream.addValue(newName);
}

void incrementCounter() {
  final currentCount = counterStream.value;
  counterStream.addValue(currentCount + 1);
}

🧱 3. Build Your UI #

class CounterPage extends StatelessWidget {
  final counterStream = StreamValue<int>(defaultValue: 0);

  CounterPage({super.key});

  void _increment() {
    counterStream.addValue(counterStream.value + 1);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('StreamValue Example')),
      body: Center(
        child: StreamValueBuilder<int>(
          streamValue: counterStream,
          builder: (context, value) {
            return Text(
              'You have pushed the button this many times: $value',
              style: Theme.of(context).textTheme.headlineMedium,
            );
          },
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _increment,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

❗ Handling Null & Error States #

StreamValueBuilder<User?>(
  streamValue: userStream,
  onNullWidget: const Center(child: CircularProgressIndicator()),
  onErrorBuilder: (error) => Center(child: Text('Error: $error')),
  builder: (context, user) {
    return Text('Hello, ${user.name}');
  },
),

πŸ§ͺ Verified Source Details #

βœ… StreamValue #

  • Uses StreamController

  • Supports null safety and default values

  • Provides .value and .error access

  • Handles manual error injection via addError(...)

  • .dispose() safely closes both controllers

βœ… StreamValueBuilder #

  • Rebuilds using StreamBuilder

  • Supports:

  • onNullWidget

  • onErrorBuilder

  • Default builder

  • Works with nullable and non-nullable streams

🀝 Contributing #

Contributions are welcome! This package focuses on simplicity. Please keep PRs in line with the existing lightweight architecture.

  • Fork it 🍴

  • Create your feature branch πŸš€

  • Push & open a PR βœ…

  • Before adding a major feature, open an issue to discuss it.

πŸ“„ License #

MIT License. See the LICENSE file for full details.

View on Pub.dev β†’

GitHub Repo β†’

#

Built with ❀️ to make Flutter state management intuitive #

1
likes
140
points
12
downloads

Publisher

unverified uploader

Weekly Downloads

a simple and lightweight state management solution for Flutter that wraps `StreamController` and `StreamBuilder` to eliminate boilerplate.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on stream_value