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
Version 1.0.10
Firebase FCM for web
Version 1.0.9
Firebase web config

View File

@ -33,49 +33,70 @@ class FirebaseApi with logger.Logging {
// Define an async function to initialize FlutterFire
Future<void> initializeFlutterFire() async {
try {
// Wait for Firebase to initialize and set `_initialized` state to true
if (kIsWeb) {
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: "AIzaSyBLn7Bz73Z1hB-OhqphBDsskOyGmpI7J8E",
authDomain: "diet4you-cb540.firebaseapp.com",
projectId: "diet4you-cb540",
storageBucket: "diet4you-cb540.appspot.com",
messagingSenderId: "534189506381",
appId: "1:534189506381:web:e885436c9be71ab4998104",
measurementId: "G-9YY4B98J99"
),
);
} else {
await Firebase.initializeApp();
try {
if (kIsWeb) {
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: "AIzaSyBLn7Bz73Z1hB-OhqphBDsskOyGmpI7J8E",
authDomain: "diet4you-cb540.firebaseapp.com",
projectId: "diet4you-cb540",
storageBucket: "diet4you-cb540.appspot.com",
messagingSenderId: "534189506381",
appId: "1:534189506381:web:e885436c9be71ab4998104",
measurementId: "G-9YY4B98J99"
),
);
} else {
await Firebase.initializeApp();
}
} on Exception catch(e) {
Sentry.captureException(e);
log("Error in Firebase init: $e");
}
appleSignInAvailable = await SignInWithApple.isAvailable();
if (kIsWeb) {
final fcmToken = await FirebaseMessaging.instance.getToken(vapidKey: "BKqkxyTqlGGI6m4gFLa-fFu9kYflyCbLkDKRKihWLqhDyR8oy1ymGzbk9lGcSDW1fd7XZiN2XYA2sDF8yjHdFPg");
FirebaseMessaging.instance.onTokenRefresh
.listen((fcmToken) {
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true, // Required to display a heads up notification
badge: true,
sound: true,
);
firebaseRegToken = await FirebaseMessaging.instance.getToken();
Cache().firebaseMessageToken = firebaseRegToken;
log("FirebaseMessaging token $firebaseRegToken");
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
log('Got a message whilst in the foreground!');
log('Message data: ${message.data}');
// Note: This callback is fired at each app startup and whenever a new
// token is generated.
log('FCM token generated');
if (message.notification != null) {
log('Message also contained a notification: ${message.notification}');
})
.onError((err) {
Sentry.captureException(err);
log("Error initializing Firebase Messaging for Web $err");
});
} else {
try {
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true, // Required to display a heads up notification
badge: true,
sound: true,
);
firebaseRegToken = await FirebaseMessaging.instance.getToken();
Cache().firebaseMessageToken = firebaseRegToken;
log("FirebaseMessaging token $firebaseRegToken");
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
log('Got a message whilst in the foreground!');
log('Message data: ${message.data}');
if (message.notification != null) {
log('Message also contained a notification: ${message.notification}');
}
});
} catch (e) {
Sentry.captureException(e);
log("Error initializing Firebase Messaging $e");
}
});
} catch (e) {
// Set `_error` state to true if Firebase initialization fails
Sentry.captureException(e);
log("Error initializing Firebase");
}
}

View File

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