flutter_stream_listener 2.0.0 copy "flutter_stream_listener: ^2.0.0" to clipboard
flutter_stream_listener: ^2.0.0 copied to clipboard

Flutter package the helps manage streams and subscriptions. Built in order to reduce the complexity of having to manually subscribe to streams and cancel subscriptions.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_stream_listener/flutter_stream_listener.dart';

void main() => runApp(const MyApp());

/// {@template my_app}
/// Example StreamListener Flutter App
/// {@endtemplate}
class MyApp extends MaterialApp {
  /// {@macro my_app}
  const MyApp({Key? key}) : super(key: key, home: const MyHomePage());
}

/// {@template my_home_page}
/// StatefulWidget which illustrates how to use [StreamListener].
/// {@endtemplate}
class MyHomePage extends StatefulWidget {
  /// {@macro my_home_page}
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var _data = 0;

  @override
  Widget build(BuildContext context) {
    const duration = Duration(seconds: 1);
    return Scaffold(
      appBar: AppBar(title: const Text('StreamListener Example')),
      body: StreamListener(
        stream: Stream.periodic(duration, (x) => x + 1).take(10),
        onData: (dynamic data) => setState(() => _data = data),
        onError: (error, stackTrace) {
          debugPrint('onError $error, $stackTrace');
        },
        onDone: () => debugPrint('onDone'),
        child: Center(child: Text('Stream Emitted $_data')),
      ),
    );
  }
}
copied to clipboard
21
likes
160
points
4.03k
downloads

Publisher

verified publisherfelangel.dev

Weekly Downloads

2024.09.27 - 2025.04.11

Flutter package the helps manage streams and subscriptions. Built in order to reduce the complexity of having to manually subscribe to streams and cancel subscriptions.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_stream_listener