behavior_subject_mixin 0.2.0 copy "behavior_subject_mixin: ^0.2.0" to clipboard
behavior_subject_mixin: ^0.2.0 copied to clipboard

A mixin that provides the state of StateNotifier as a stream of BehaviorSubject.

example/lib/main.dart

import 'dart:async';

import 'package:behavior_subject_mixin/behavior_subject_mixin.dart';
import 'package:state_notifier/state_notifier.dart';

class CounterNotifier extends StateNotifier<int> with BehaviorSubjectMixin {
  CounterNotifier() : super(0);

  void increment() => state++;
}

void main() {
  final counterNotifier = CounterNotifier();
  final subscription = counterNotifier.stream.listen((currentState) {
    print('count is $currentState.');
  });

  // count is 0.

  counterNotifier.increment(); // count is 1.
  counterNotifier.increment(); // count is 2.
  counterNotifier.increment(); // count is 3.

  Timer.run(subscription.cancel);
}
3
likes
40
pub points
0%
popularity

Publisher

unverified uploader

A mixin that provides the state of StateNotifier as a stream of BehaviorSubject.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

rxdart, state_notifier

More

Packages that depend on behavior_subject_mixin