2019-01-27 17:37:44 +01:00
|
|
|
import 'dart:async';
|
2019-01-23 09:50:51 +01:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:rxdart/subjects.dart';
|
|
|
|
import 'package:rxdart/rxdart.dart';
|
|
|
|
|
|
|
|
class NotificationBloc {
|
2019-01-27 17:37:44 +01:00
|
|
|
final _count = BehaviorSubject(seedValue: 0);
|
|
|
|
final _updater = StreamController();
|
2019-01-23 09:50:51 +01:00
|
|
|
|
2019-01-27 17:37:44 +01:00
|
|
|
Stream<int> get count => _count.stream;
|
|
|
|
Sink get countUpdate => _updater.sink;
|
2019-01-23 09:50:51 +01:00
|
|
|
|
|
|
|
NotificationBloc() {
|
2019-01-27 17:37:44 +01:00
|
|
|
_updater.stream.listen((_) {
|
|
|
|
_count.add(99);
|
2019-01-23 09:50:51 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NotificationProvider extends InheritedWidget {
|
|
|
|
final NotificationBloc bloc;
|
|
|
|
|
|
|
|
NotificationProvider({
|
|
|
|
Key key,
|
|
|
|
Widget child,
|
|
|
|
@required NotificationBloc bloc,
|
|
|
|
}) : bloc = bloc,
|
|
|
|
super(key: key, child: child);
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool updateShouldNotify(InheritedWidget oldWidget) => true;
|
|
|
|
|
|
|
|
static NotificationBloc of(BuildContext context) =>
|
|
|
|
(context.inheritFromWidgetOfExactType(NotificationProvider)
|
|
|
|
as NotificationProvider)
|
|
|
|
.bloc;
|
|
|
|
}
|