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 all commits
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
3 changes: 0 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.com.shekarmudaliyar.social_share"
Expand Down
93 changes: 0 additions & 93 deletions lib/firebase_options.dart

This file was deleted.

156 changes: 0 additions & 156 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
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 +21,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 +32,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 +45,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 @@ -332,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) {});
}
12 changes: 0 additions & 12 deletions lib/services/database_mutation_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,6 @@ class DataBaseMutationFunctions {
}
return false;
}
if (exception.graphqlErrors[i].message ==
notifFeatureNotInstalled.message) {
if (showSnackBar) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => navigationService.showTalawaErrorDialog(
"Notification Feature is not installed",
MessageType.error,
),
);
}
return false;
}
}
// if the error is unknown

Expand Down
1 change: 1 addition & 0 deletions lib/utils/event_queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class EventQueries {
///
/// This function generates a GraphQL query string to retrieve events
/// based on the provided organization ID.

String fetchOrgEvents(String orgId) {
return """
query {
Expand Down
32 changes: 1 addition & 31 deletions lib/utils/queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,7 @@ class Queries {
}
}
refreshToken
androidFirebaseOptions {
apiKey
appId
messagingSenderId
projectId
storageBucket
}
iosFirebaseOptions {
apiKey
appId
messagingSenderId
projectId
storageBucket
iosClientId
iosBundleId
}

}
}
""";
Expand Down Expand Up @@ -193,21 +178,6 @@ class Queries {
""";
}

/// To save fcm token the backend fro notification.
///
/// **params**:
/// * `token`: fcm token, read firebase docs for more info
///
/// **returns**:
/// * `String`: return the mutation
String saveFcmToken(String? token) {
return """
mutation {
saveFcmToken(token: "$token")
}
""";
}

/// logout muiation.
///
/// **params**:
Expand Down
Loading
Loading