Last active
January 14, 2019 20:28
-
-
Save axross/1f5129204ae9ab0b75e491ddf3702d90 to your computer and use it in GitHub Desktop.
Wrapper object to handle cloud messaging in an appropriate way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Saya suka