Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Removed all references to Google firebase #2257

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data
<!-- <meta-data
Abhisheksainii marked this conversation as resolved.
Show resolved Hide resolved
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
android:value="high_importance_channel" /> -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.com.shekarmudaliyar.social_share"
Expand Down
178 changes: 89 additions & 89 deletions lib/firebase_options.dart
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
// File generated by FlutterFire CLI.
// // File generated by FlutterFire CLI.

Abhisheksainii marked this conversation as resolved.
Show resolved Hide resolved
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show TargetPlatform, defaultTargetPlatform, kIsWeb;
// import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
// import 'package:flutter/foundation.dart'
// show TargetPlatform, defaultTargetPlatform, kIsWeb;

/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
/// options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
/// Builds and returns [FirebaseOptions] based on the current platform.
///
/// Switches on the current platform and calls [android] or [iOS]
/// methods accordingly to build the [FirebaseOptions]. Throws
/// [UnsupportedError] if the platform is other than these two.
///
/// **params**:
/// * `androidFirebaseOptions`: Firebase Options for Android
/// * `iosFirebaseOptions`: Firebase Options for iOS
///
/// **returns**:
/// * `FirebaseOptions`: The [FirebaseOptions] built according to the platform.
static FirebaseOptions currentPlatform(
Map<String, dynamic> androidFirebaseOptions,
Map<String, dynamic> iosFirebaseOptions,
) {
if (kIsWeb) {
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for web - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android(androidFirebaseOptions);
case TargetPlatform.iOS:
return ios(iosFirebaseOptions);
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}
// /// Default [FirebaseOptions] for use with your Firebase apps.
// ///
// /// Example:
// /// ```dart
// /// import 'firebase_options.dart';
// /// // ...
// /// await Firebase.initializeApp(
// /// options: DefaultFirebaseOptions.currentPlatform,
// /// );
// /// ```
// class DefaultFirebaseOptions {
// /// Builds and returns [FirebaseOptions] based on the current platform.
// ///
// /// Switches on the current platform and calls [android] or [iOS]
// /// methods accordingly to build the [FirebaseOptions]. Throws
// /// [UnsupportedError] if the platform is other than these two.
// ///
// /// **params**:
// /// * `androidFirebaseOptions`: Firebase Options for Android
// /// * `iosFirebaseOptions`: Firebase Options for iOS
// ///
// /// **returns**:
// /// * `FirebaseOptions`: The [FirebaseOptions] built according to the platform.
// static FirebaseOptions currentPlatform(
// Map<String, dynamic> androidFirebaseOptions,
// Map<String, dynamic> iosFirebaseOptions,
// ) {
// if (kIsWeb) {
// throw UnsupportedError(
// 'DefaultFirebaseOptions have not been configured for web - '
// 'you can reconfigure this by running the FlutterFire CLI again.',
// );
// }
// switch (defaultTargetPlatform) {
// case TargetPlatform.android:
// return android(androidFirebaseOptions);
// case TargetPlatform.iOS:
// return ios(iosFirebaseOptions);
// case TargetPlatform.macOS:
// throw UnsupportedError(
// 'DefaultFirebaseOptions have not been configured for macos - '
// 'you can reconfigure this by running the FlutterFire CLI again.',
// );
// default:
// throw UnsupportedError(
// 'DefaultFirebaseOptions are not supported for this platform.',
// );
// }
// }

/// Scaffolds androidFirebaseOptions around FirebaseOptions.
///
/// **params**:
/// * `androidFirebaseOptions`: The options which we want to scaffold
///
/// **returns**:
/// * `FirebaseOptions`: Scaffolded FirebaseOptions
static FirebaseOptions android(Map<String, dynamic> androidFirebaseOptions) =>
FirebaseOptions(
apiKey: androidFirebaseOptions['apiKey'] as String,
appId: androidFirebaseOptions['appId'] as String,
messagingSenderId:
androidFirebaseOptions['messagingSenderId'] as String,
projectId: androidFirebaseOptions['projectId'] as String,
storageBucket: androidFirebaseOptions['storageBucket'] as String,
);
// /// Scaffolds androidFirebaseOptions around FirebaseOptions.
// ///
// /// **params**:
// /// * `androidFirebaseOptions`: The options which we want to scaffold
// ///
// /// **returns**:
// /// * `FirebaseOptions`: Scaffolded FirebaseOptions
// static FirebaseOptions android(Map<String, dynamic> androidFirebaseOptions) =>
// FirebaseOptions(
// apiKey: androidFirebaseOptions['apiKey'] as String,
// appId: androidFirebaseOptions['appId'] as String,
// messagingSenderId:
// androidFirebaseOptions['messagingSenderId'] as String,
// projectId: androidFirebaseOptions['projectId'] as String,
// storageBucket: androidFirebaseOptions['storageBucket'] as String,
// );

/// Scaffolds iosFirebaseOptions around FirebaseOptions.
///
/// more_info_if_required
///
/// **params**:
/// * `iosFirebaseOptions`: The options which we want to scaffold
///
/// **returns**:
/// * `FirebaseOptions`: Scaffolded FirebaseOptions
static FirebaseOptions ios(Map<String, dynamic> iosFirebaseOptions) =>
FirebaseOptions(
apiKey: iosFirebaseOptions['apiKey'] as String,
appId: iosFirebaseOptions['appId'] as String,
messagingSenderId: iosFirebaseOptions['messagingSenderId'] as String,
projectId: iosFirebaseOptions['projectId'] as String,
storageBucket: iosFirebaseOptions['storageBucket'] as String,
iosClientId: iosFirebaseOptions['iosClientId'] as String,
iosBundleId: iosFirebaseOptions['iosBundleId'] as String,
);
}
// /// Scaffolds iosFirebaseOptions around FirebaseOptions.
// ///
// /// more_info_if_required
// ///
// /// **params**:
// /// * `iosFirebaseOptions`: The options which we want to scaffold
// ///
// /// **returns**:
// /// * `FirebaseOptions`: Scaffolded FirebaseOptions
// static FirebaseOptions ios(Map<String, dynamic> iosFirebaseOptions) =>
// FirebaseOptions(
// apiKey: iosFirebaseOptions['apiKey'] as String,
// appId: iosFirebaseOptions['appId'] as String,
// messagingSenderId: iosFirebaseOptions['messagingSenderId'] as String,
// projectId: iosFirebaseOptions['projectId'] as String,
// storageBucket: iosFirebaseOptions['storageBucket'] as String,
// iosClientId: iosFirebaseOptions['iosClientId'] as String,
// iosBundleId: iosFirebaseOptions['iosBundleId'] as String,
// );
// }
155 changes: 0 additions & 155 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
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/material.dart';
import 'package:flutter/services.dart' as fs;
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart' as path;
import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:talawa/constants/custom_theme.dart';
import 'package:talawa/constants/quick_actions.dart';
import 'package:talawa/firebase_options.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/asymetric_keys/asymetric_keys.dart';
import 'package:talawa/models/organization/org_info.dart';
Expand All @@ -26,51 +22,6 @@ import 'package:talawa/view_model/lang_view_model.dart';
import 'package:talawa/view_model/theme_view_model.dart';
import 'package:talawa/views/base_view.dart';

/// Define a top-level named handler which background/terminated messages will call.
///
/// To verify things are working, check out the native platform logs.
/// **params**:
/// * `message`: incoming messsage.
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled message background activities are successful.
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
final Directory dir = await path.getApplicationDocumentsDirectory();
Hive.init(dir.path);
await setUpFirebaseKeys();
await setUpFirebase();
}

/// Initializes the firebase in the app according to the userplatform (android/iOS).
///
/// **params**:
/// None
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled Firebase is setted up in app.
Future<void> setUpFirebase() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform(
androidFirebaseOptions,
iosFirebaseOptions,
),
);
}

/// HashMap of Firebase options for android.
late Map<String, dynamic> androidFirebaseOptions;

/// HashMap of Firebase options for android.
late Map<String, dynamic> iosFirebaseOptions;

/// Create a [AndroidNotificationChannel] for heads up notifications.
late AndroidNotificationChannel channel;

/// Initialize the [FlutterLocalNotificationsPlugin] package.
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

/// First function to initialize the application, invoked automatically.
///
/// **params**:
Expand All @@ -82,26 +33,6 @@ Future<void> main() async {
// Returns an instance of the binding that implements WidgetsBinding.
WidgetsFlutterBinding.ensureInitialized();

if (!kIsWeb) {
channel = const AndroidNotificationChannel(
'high_importance_channel', // id
'High Importance Notifications', // title
description:
'This channel is used for important notifications.', // description
importance: Importance.high,
);

flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

// Create an Android Notification Channel.
// We use this channel in the `AndroidManifest.xml` file to override the
// default FCM channel to enable heads up notifications.
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
}

final Directory dir = await path.getApplicationDocumentsDirectory();
Hive
..init(dir.path)
Expand All @@ -115,52 +46,11 @@ Future<void> main() async {
await Hive.openBox('pluginBox');
await Hive.openBox('url');

final urlBox = await Hive.openBox('url');

try {
if (urlBox.get('url') != null) {
await setUpFirebaseKeys();

await setUpFirebase();
await setUpFirebaseMessaging();
}
} catch (e) {
print("Firebase not working");
}

setupLocator();
// The runApp() function takes the given Widget and makes it the root of the widget tree.
runApp(MyApp());
}

/// Initializes the firebase keys in the app according to the userplatform (android/iOS).
///
/// **params**:
/// None
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled Firebase keys are setted up.
Future<void> setUpFirebaseKeys() async {
final androidFirebaseOptionsBox =
await Hive.openBox('androidFirebaseOptions');
final androidFirebaseOptionsMap = androidFirebaseOptionsBox
.get('androidFirebaseOptions') as Map<dynamic, dynamic>?;

final iosFirebaseOptionsBox = await Hive.openBox('iosFirebaseOptions');
final iosFirebaseOptionsMap =
iosFirebaseOptionsBox.get('iosFirebaseOptions') as Map<dynamic, dynamic>?;
if (androidFirebaseOptionsMap != null) {
androidFirebaseOptions = androidFirebaseOptionsMap.map((key, value) {
return MapEntry(key.toString(), value);
});
}
if (iosFirebaseOptionsMap != null) {
iosFirebaseOptions = iosFirebaseOptionsMap.map((key, value) {
return MapEntry(key.toString(), value);
});
}
}

/// Main widget that sets up the quick actions, internationalization, routing , notifications.
class MyApp extends StatefulWidget {
// This widget is the root of your application.
Expand Down Expand Up @@ -331,48 +221,3 @@ class DemoViewModel extends BaseModel {
/// * `String`: title of the model
String get title => _title;
}

/// Set up firebase instance, enbables messaging,listens to icoming messages.
///
/// **params**:
/// None
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled Firebase is setted up.
Future<void> setUpFirebaseMessaging() async {
/// Set the background messaging handler early on, as a named top-level function
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

// Update the iOS foreground notification presentation options to allow heads up notifications.
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);

FirebaseMessaging.instance
.getInitialMessage()
.then((RemoteMessage? message) {});

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
final RemoteNotification? notification = message.notification;
final AndroidNotification? android = message.notification?.android;
if (notification != null && android != null && !kIsWeb) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
channelDescription: channel.description,
icon: 'launch_background',
),
),
);
}
});

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {});
}
Loading
Loading