stream_listenable 1.0.0 copy "stream_listenable: ^1.0.0" to clipboard
stream_listenable: ^1.0.0 copied to clipboard

Bridge Dart Streams into Flutter's Listenable/ValueListenable interfaces. Lazily subscribes and auto-cancels.

example/example.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:stream_listenable/stream_listenable.dart';

/// A simple counter that emits values via a Stream.
Stream<int> counterStream() async* {
  var i = 0;
  while (true) {
    await Future<void>.delayed(const Duration(seconds: 1));
    yield ++i;
  }
}

class CounterPage extends StatefulWidget {
  const CounterPage({super.key});

  @override
  State<CounterPage> createState() => _CounterPageState();
}

class _CounterPageState extends State<CounterPage> {
  late final ValueListenable<int> _counter;

  @override
  void initState() {
    super.initState();
    _counter = counterStream().asValueListenable(initialValue: 0);
  }

  @override
  void dispose() {
    (_counter as StreamValueListenable<int>).dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<int>(
      valueListenable: _counter,
      builder: (context, value, child) {
        return Text('Counter: $value');
      },
    );
  }
}
0
likes
160
points
8
downloads

Documentation

API reference

Publisher

verified publisherjacopoguzzo.dev

Weekly Downloads

Bridge Dart Streams into Flutter's Listenable/ValueListenable interfaces. Lazily subscribes and auto-cancels.

Repository (GitHub)
View/report issues

Topics

#stream #listenable #valuelistenable #changenotifier

License

MIT (license)

Dependencies

flutter

More

Packages that depend on stream_listenable