mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-21 20:39:22 +00:00
Integrate Firebase
This commit is contained in:
parent
0c75575a70
commit
f0f2f06ec2
@ -104,3 +104,5 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
}
|
||||
|
||||
apply plugin: 'com.google.gms.google-services'
|
39
android/app/src/beta/google-services.json
Normal file
39
android/app/src/beta/google-services.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "1007877315904",
|
||||
"project_id": "comunic-ae92c",
|
||||
"storage_bucket": "comunic-ae92c.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:1007877315904:android:d1db6417ef236d850aeea5",
|
||||
"android_client_info": {
|
||||
"package_name": "org.communiquons.beta"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAfhNbEhHkmVYPQK200rJGxH9hc7qHlcwU"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
68
android/app/src/main/google-services.json
Normal file
68
android/app/src/main/google-services.json
Normal file
@ -0,0 +1,68 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "1007877315904",
|
||||
"project_id": "comunic-ae92c",
|
||||
"storage_bucket": "comunic-ae92c.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:1007877315904:android:d1db6417ef236d850aeea5",
|
||||
"android_client_info": {
|
||||
"package_name": "org.communiquons.beta"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAfhNbEhHkmVYPQK200rJGxH9hc7qHlcwU"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:1007877315904:android:c30eb760a5ffca750aeea5",
|
||||
"android_client_info": {
|
||||
"package_name": "org.communiquons.comunic"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAfhNbEhHkmVYPQK200rJGxH9hc7qHlcwU"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
@ -6,6 +6,9 @@ buildscript {
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.4'
|
||||
|
||||
// Firebase
|
||||
classpath 'com.google.gms:google-services:4.3.5'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,16 +5,19 @@
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
import 'package:file_picker/src/file_picker_web.dart';
|
||||
import 'package:firebase_core_web/firebase_core_web.dart';
|
||||
import 'package:firebase_messaging_web/firebase_messaging_web.dart';
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
import 'package:shared_preferences_web/shared_preferences_web.dart';
|
||||
import 'package:url_launcher_web/url_launcher_web.dart';
|
||||
import 'package:video_player_web/video_player_web.dart';
|
||||
import 'package:wakelock_web/wakelock_web.dart';
|
||||
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
|
||||
// ignore: public_member_api_docs
|
||||
void registerPlugins(Registrar registrar) {
|
||||
FilePickerWeb.registerWith(registrar);
|
||||
FirebaseCoreWeb.registerWith(registrar);
|
||||
FirebaseMessagingWeb.registerWith(registrar);
|
||||
SharedPreferencesPlugin.registerWith(registrar);
|
||||
UrlLauncherPlugin.registerWith(registrar);
|
||||
VideoPlayerPlugin.registerWith(registrar);
|
||||
|
26
lib/helpers/firebase_messaging_helper.dart
Normal file
26
lib/helpers/firebase_messaging_helper.dart
Normal file
@ -0,0 +1,26 @@
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
/// Firebase messaging helper
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
bool _isFirebaseReady = false;
|
||||
|
||||
class FirebaseMessagingHelper {
|
||||
/// Pre configure notifications
|
||||
static Future<void> preConfigure() async {
|
||||
if (!_isFirebaseReady) await Firebase.initializeApp();
|
||||
_isFirebaseReady = true;
|
||||
|
||||
final settings = await FirebaseMessaging.instance.requestPermission();
|
||||
|
||||
if (settings.authorizationStatus != AuthorizationStatus.authorized)
|
||||
throw new Exception("The user did not authorize notifications!");
|
||||
}
|
||||
|
||||
/// Get a Firebase access token
|
||||
static Future<String> getToken() async {
|
||||
return await FirebaseMessaging.instance.getToken();
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import 'package:comunic/helpers/firebase_messaging_helper.dart';
|
||||
import 'package:comunic/helpers/independent_push_notifications_helper.dart';
|
||||
import 'package:comunic/helpers/push_notifications_helper.dart';
|
||||
import 'package:comunic/helpers/server_config_helper.dart';
|
||||
@ -111,13 +112,15 @@ class _PushNotificationsConfigurationRouteState
|
||||
|
||||
Future<void> _submit() async {
|
||||
try {
|
||||
String firebaseToken = "";
|
||||
|
||||
switch (currStatus) {
|
||||
case PushNotificationsStatus.DISABLED:
|
||||
break;
|
||||
|
||||
case PushNotificationsStatus.FIREBASE:
|
||||
// TODO: Handle this case.
|
||||
throw new Exception("Firebase not supported yet!");
|
||||
await FirebaseMessagingHelper.preConfigure();
|
||||
firebaseToken = await FirebaseMessagingHelper.getToken();
|
||||
break;
|
||||
|
||||
case PushNotificationsStatus.INDEPENDENT:
|
||||
@ -130,7 +133,8 @@ class _PushNotificationsConfigurationRouteState
|
||||
}
|
||||
|
||||
await PushNotificationsHelper.clearLocalStatus();
|
||||
await PushNotificationsHelper.setNewStatus(currStatus);
|
||||
await PushNotificationsHelper.setNewStatus(currStatus,
|
||||
firebaseToken: firebaseToken);
|
||||
await PushNotificationsHelper.refreshLocalStatus();
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
42
pubspec.lock
42
pubspec.lock
@ -190,6 +190,48 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
firebase_core:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: firebase_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
firebase_core_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_core_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
firebase_core_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_core_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
firebase_messaging:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: firebase_messaging
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "9.0.0"
|
||||
firebase_messaging_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_messaging_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
firebase_messaging_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_messaging_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -126,6 +126,10 @@ dependencies:
|
||||
# Image cropper
|
||||
image_cropper: ^1.4.0
|
||||
|
||||
# Firebase cloud messaging (for push notifications)
|
||||
firebase_core: ^1.0.1
|
||||
firebase_messaging: ^9.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
Loading…
Reference in New Issue
Block a user