Created
August 5, 2019 09:23
-
-
Save SebastianEngel/0769b50cb2ba6962248341f1fbd508f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'package:firebase_messaging/firebase_messaging.dart'; | |
class PushNotificationsManager { | |
PushNotificationsManager._(); | |
factory PushNotificationsManager() => _instance; | |
static final PushNotificationsManager _instance = PushNotificationsManager._(); | |
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); | |
bool _initialized = false; | |
Future<void> init() async { | |
if (!_initialized) { | |
// For iOS request permission first. | |
_firebaseMessaging.requestNotificationPermissions(); | |
_firebaseMessaging.configure(); | |
// For testing purposes print the Firebase Messaging token | |
String token = await _firebaseMessaging.getToken(); | |
print("FirebaseMessaging token: $token"); | |
_initialized = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some replacements are needed:
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
and
See: https://firebase.flutter.dev/docs/migration/#messaging