Skip to content

Instantly share code, notes, and snippets.

@axross
Last active January 14, 2019 20:28
Show Gist options
  • Save axross/1f5129204ae9ab0b75e491ddf3702d90 to your computer and use it in GitHub Desktop.
Save axross/1f5129204ae9ab0b75e491ddf3702d90 to your computer and use it in GitHub Desktop.
Wrapper object to handle cloud messaging in an appropriate way
import 'dart:async';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:meta/meta.dart';
class MessageTray {
MessageTray({@required FirebaseMessaging messaging})
: assert(messaging != null),
_onMessage = StreamController(),
_onResume = StreamController(),
_onLaunch = StreamController() {
messaging.configure(
onMessage: (payload) async => _onMessage.sink.add(payload),
onResume: (payload) async => _onResume.sink.add(payload),
onLaunch: (payload) async => _onLaunch.sink.add(payload),
);
}
final StreamController<Map<String, dynamic>> _onMessage;
final StreamController<Map<String, dynamic>> _onResume;
final StreamController<Map<String, dynamic>> _onLaunch;
Stream<Map<String, dynamic>> get onMessage => _onMessage.stream;
Stream<Map<String, dynamic>> get onResume => _onResume.stream;
Stream<Map<String, dynamic>> get onLaunch => _onLaunch.stream;
}
@andihatta
Copy link

Saya suka

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment