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

An event without data, using StreamController to be used in flutter projects.

live_event #

pub package

An event without data, using StreamController to be used in flutter projects.

Getting started #

Have you been creating StreamControllers without data like this?

class MyBloc {
  final _someEvent = StreamController<void>();
  
  Stream get someEvent => _someEvent.stream;
  
  void logic() {
    _someEvent.sink.add(null);
  }
}

Now you don't need to pass null to indicate it's just an event:

import 'package:live_event/live_event.dart';

class MyBloc {
  final _someEvent = LiveEvent();
  
  Stream get someEvent => _someEvent.stream;
  
  void logic() {
    _someEvent.fire(); // here we don't need to pass null anymore!
  }
}

Usage #

To use this plugin, add live_event as a dependency in your pubspec.yaml file.

dependencies:
  live_event: ^lastVersion

Example #

import 'package:live_event/live_event.dart';

class MyBloc {
  final _someEvent = LiveEvent();
  
  Stream get someEvent => _someEvent.stream;
  
  void logic() {
    _someEvent.fire();
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State createState() => _HomeState();
}

class _HomeState extends State<HomePage> {
  late MyBloc bloc;
  
  @override
  void initState() {
    super.initState();
    bloc = MyBloc();
    
    bloc.someEvent.listen((_) {
      // do something about this event
    });
  }
}
4
likes
160
pub points
11%
popularity

Publisher

verified publisherbuildtoapp.com

An event without data, using StreamController to be used in flutter projects.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on live_event