This commit is contained in:
Tibor Bossanyi 2023-02-22 22:20:11 +01:00
parent 895fe0d022
commit 3cd584436b
3 changed files with 60 additions and 36 deletions

View File

@ -1,5 +1,8 @@
Workout Test and Diet 4 You Common Util Functions Workout Test and Diet 4 You Common Util Functions
Version 1.0.10
Firebase FCM for web
Version 1.0.9 Version 1.0.9
Firebase web config Firebase web config

View File

@ -34,7 +34,7 @@ class FirebaseApi with logger.Logging {
// Define an async function to initialize FlutterFire // Define an async function to initialize FlutterFire
Future<void> initializeFlutterFire() async { Future<void> initializeFlutterFire() async {
try { try {
// Wait for Firebase to initialize and set `_initialized` state to true
if (kIsWeb) { if (kIsWeb) {
await Firebase.initializeApp( await Firebase.initializeApp(
options: const FirebaseOptions( options: const FirebaseOptions(
@ -50,10 +50,30 @@ class FirebaseApi with logger.Logging {
} else { } else {
await Firebase.initializeApp(); await Firebase.initializeApp();
} }
} on Exception catch(e) {
Sentry.captureException(e);
log("Error in Firebase init: $e");
}
appleSignInAvailable = await SignInWithApple.isAvailable(); appleSignInAvailable = await SignInWithApple.isAvailable();
if (kIsWeb) {
final fcmToken = await FirebaseMessaging.instance.getToken(vapidKey: "BKqkxyTqlGGI6m4gFLa-fFu9kYflyCbLkDKRKihWLqhDyR8oy1ymGzbk9lGcSDW1fd7XZiN2XYA2sDF8yjHdFPg");
FirebaseMessaging.instance.onTokenRefresh
.listen((fcmToken) {
// Note: This callback is fired at each app startup and whenever a new
// token is generated.
log('FCM token generated');
})
.onError((err) {
Sentry.captureException(err);
log("Error initializing Firebase Messaging for Web $err");
});
} else {
try {
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true, // Required to display a heads up notification alert: true, // Required to display a heads up notification
badge: true, badge: true,
@ -64,6 +84,7 @@ class FirebaseApi with logger.Logging {
log("FirebaseMessaging token $firebaseRegToken"); log("FirebaseMessaging token $firebaseRegToken");
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessage.listen((RemoteMessage message) { FirebaseMessaging.onMessage.listen((RemoteMessage message) {
log('Got a message whilst in the foreground!'); log('Got a message whilst in the foreground!');
log('Message data: ${message.data}'); log('Message data: ${message.data}');
@ -73,9 +94,9 @@ class FirebaseApi with logger.Logging {
} }
}); });
} catch (e) { } catch (e) {
// Set `_error` state to true if Firebase initialization fails
Sentry.captureException(e); Sentry.captureException(e);
log("Error initializing Firebase"); log("Error initializing Firebase Messaging $e");
}
} }
} }

View File

@ -1,6 +1,6 @@
name: workouttest_util name: workouttest_util
description: Workout Test app and web functions. description: Workout Test app and web functions.
version: 1.0.8 version: 1.0.10
homepage: homepage:
environment: environment: