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 '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; | |
} | |
} | |
} |
Future main() async {
PushNotificationsManager().init(); <--
That's the way I do it.
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
PushNotificationsManager().init();
runApp(MyApp());
}
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
_firebaseMessaging.requestNotificationPermissions();
_firebaseMessaging.configure();
These method calls not exist in latest flutter_message version.
firebase_messaging: ^10.0.5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@SebastianEngel Could you share an example how to call the init() method? Thank you