TF-1202: Configure ENV for FCM
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// File generated by FlutterFire CLI.
|
||||
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
|
||||
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
|
||||
import 'package:flutter/foundation.dart'
|
||||
show defaultTargetPlatform, kIsWeb, TargetPlatform;
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
class DefaultFirebaseOptions {
|
||||
static FirebaseOptions get currentPlatform {
|
||||
if (kIsWeb) {
|
||||
return web;
|
||||
}
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.android:
|
||||
return android;
|
||||
case TargetPlatform.iOS:
|
||||
return ios;
|
||||
case TargetPlatform.macOS:
|
||||
throw UnsupportedError(
|
||||
'DefaultFirebaseOptions have not been configured for macos - '
|
||||
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||
);
|
||||
case TargetPlatform.windows:
|
||||
throw UnsupportedError(
|
||||
'DefaultFirebaseOptions have not been configured for windows - '
|
||||
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||
);
|
||||
case TargetPlatform.linux:
|
||||
throw UnsupportedError(
|
||||
'DefaultFirebaseOptions have not been configured for linux - '
|
||||
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||
);
|
||||
default:
|
||||
throw UnsupportedError(
|
||||
'DefaultFirebaseOptions are not supported for this platform.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static FirebaseOptions web = FirebaseOptions(
|
||||
apiKey: dotenv.get('FIREBASE_WEB_API_KEY', fallback: ''),
|
||||
appId: dotenv.get('FIREBASE_WEB_APP_ID', fallback: ''),
|
||||
messagingSenderId: dotenv.get('FIREBASE_WEB_MESSAGING_SENDER_ID', fallback: ''),
|
||||
projectId: dotenv.get('FIREBASE_WEB_PROJECT_ID', fallback: ''),
|
||||
authDomain: dotenv.get('FIREBASE_WEB_AUTH_DOMAIN', fallback: ''),
|
||||
databaseURL: dotenv.get('FIREBASE_WEB_DATABASE_URL', fallback: ''),
|
||||
storageBucket: dotenv.get('FIREBASE_WEB_STORAGE_BUCKET', fallback: ''),
|
||||
);
|
||||
|
||||
static FirebaseOptions android = FirebaseOptions(
|
||||
apiKey: dotenv.get('FIREBASE_ANDROID_API_KEY', fallback: ''),
|
||||
appId: dotenv.get('FIREBASE_ANDROID_APP_ID', fallback: ''),
|
||||
messagingSenderId: dotenv.get('FIREBASE_ANDROID_MESSAGING_SENDER_ID', fallback: ''),
|
||||
projectId: dotenv.get('FIREBASE_ANDROID_PROJECT_ID', fallback: ''),
|
||||
databaseURL: dotenv.get('FIREBASE_ANDROID_DATABASE_URL', fallback: ''),
|
||||
storageBucket: dotenv.get('FIREBASE_ANDROID_STORAGE_BUCKET', fallback: ''),
|
||||
);
|
||||
|
||||
static FirebaseOptions ios = FirebaseOptions(
|
||||
apiKey: dotenv.get('FIREBASE_IOS_API_KEY', fallback: ''),
|
||||
appId: dotenv.get('FIREBASE_IOS_APP_ID', fallback: ''),
|
||||
messagingSenderId: dotenv.get('FIREBASE_IOS_MESSAGING_SENDER_ID', fallback: ''),
|
||||
projectId: dotenv.get('FIREBASE_IOS_PROJECT_ID', fallback: ''),
|
||||
databaseURL: dotenv.get('FIREBASE_IOS_DATABASE_URL', fallback: ''),
|
||||
storageBucket: dotenv.get('FIREBASE_IOS_STORAGE_BUCKET', fallback: ''),
|
||||
iosClientId: dotenv.get('FIREBASE_IOS_CLIENT_ID', fallback: ''),
|
||||
iosBundleId: dotenv.get('FIREBASE_IOS_BUNDLE_ID', fallback: ''),
|
||||
);
|
||||
}
|
||||
@@ -4,12 +4,12 @@ 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_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:model/firebase/firebase_dto.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/save_firebase_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/firebase_options.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/presentation/firebase_options.dart';
|
||||
import 'notification_strings.dart';
|
||||
|
||||
final StreamController<NotificationResponse?> selectNotificationStream =
|
||||
@@ -17,6 +17,7 @@ StreamController<NotificationResponse?>.broadcast();
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
await dotenv.load(fileName: 'env.file');
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
await NotificationService.displayPushNotification(message);
|
||||
}
|
||||
@@ -44,13 +45,6 @@ class NotificationService {
|
||||
static get _flutterLocalNotificationsPlugin =>
|
||||
FlutterLocalNotificationsPlugin();
|
||||
|
||||
static final BehaviorSubject<NotificationResponse?>
|
||||
_notificationActionStream =
|
||||
BehaviorSubject<NotificationResponse?>.seeded(null);
|
||||
|
||||
static Stream<NotificationResponse?> get notificationActionStream =>
|
||||
_notificationActionStream.stream;
|
||||
|
||||
static Stream<String> get onTokenRefresh => _firebaseMessaging.onTokenRefresh;
|
||||
static bool _isFlutterLocalNotificationsInitialized = false;
|
||||
|
||||
@@ -130,7 +124,6 @@ class NotificationService {
|
||||
selectNotificationStream.stream
|
||||
.listen((event) => event)
|
||||
.onData((data) async {
|
||||
_notificationActionStream.add(data);
|
||||
switch (data?.notificationResponseType) {
|
||||
case NotificationResponseType.selectedNotification:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user