Skip to content

Commit

Permalink
fix: check if we have an app initialized before getting token, if not…
Browse files Browse the repository at this point in the history
…, init
  • Loading branch information
Oliver-Zimmerman committed Feb 7, 2025
1 parent d00e484 commit 6a2c86b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/model/profile_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
Expand Down Expand Up @@ -51,6 +52,10 @@ class Profile {
Future<String?> getNotificationTokenForPlatform() async {
var token;
if (defaultTargetPlatform == TargetPlatform.android) {
// If no apps are initialized, initialize one now.
if (Firebase.apps.isEmpty) {
await Firebase.initializeApp();
}
token = (await FirebaseMessaging.instance.getToken())!;
} else if (Platform.isIOS) {
token = await FlutterCallkitIncoming.getDevicePushTokenVoIP();
Expand Down

0 comments on commit 6a2c86b

Please sign in to comment.