Skip to content

Commit

Permalink
notification service added
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank-lol committed Feb 22, 2024
1 parent 8cf5fb6 commit f5f6dc3
Show file tree
Hide file tree
Showing 17 changed files with 361 additions and 126 deletions.
6 changes: 6 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id "com.google.gms.google-services"
}

def localProperties = new Properties()
Expand All @@ -22,6 +24,8 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.google.gms.google-services'

android {
namespace "com.example.anom_alert"
compileSdkVersion flutter.compileSdkVersion
Expand Down Expand Up @@ -67,4 +71,6 @@ flutter {

dependencies {
implementation 'com.android.support:multidex:2.0.1'
implementation platform('com.google.firebase:firebase-bom:32.7.2')
implementation 'com.google.firebase:firebase-analytics'
}
76 changes: 7 additions & 69 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -1,88 +1,26 @@
{
"project_info": {
"project_number": "555773019046",
"firebase_url": "https://shashank-flutter-default-rtdb.firebaseio.com",
"project_id": "shashank-flutter",
"storage_bucket": "shashank-flutter.appspot.com"
"project_number": "685258239678",
"project_id": "anom-alert",
"storage_bucket": "anom-alert.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:555773019046:android:f5e6233cbe0aa03090c567",
"mobilesdk_app_id": "1:685258239678:android:244ce9bcc7648f48a878ef",
"android_client_info": {
"package_name": "com.example.anom_alert"
}
},
"oauth_client": [
{
"client_id": "555773019046-7mlr7pml8ijqe5uh0jrl9h09bpnkdffc.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.anom_alert",
"certificate_hash": "fcf6367d5b972e7a89d929bb8eefcb8178b2c924"
}
},
{
"client_id": "555773019046-8t36tl4ar0g6vqkjibpucmra7bue509l.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDmPZG9I0BfJhKxrQYFnAeU6p0tX4Ykovw"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "555773019046-8t36tl4ar0g6vqkjibpucmra7bue509l.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "555773019046-1g8er5ph0mf4g7h1vbmc9b5q2olev41u.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.jgecNotice.RunnerTests"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:555773019046:android:8c0a9f6f8e0b627890c567",
"android_client_info": {
"package_name": "com.example.jgec_notice"
}
},
"oauth_client": [
{
"client_id": "555773019046-8t36tl4ar0g6vqkjibpucmra7bue509l.apps.googleusercontent.com",
"client_type": 3
}
],
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyDmPZG9I0BfJhKxrQYFnAeU6p0tX4Ykovw"
"current_key": "AIzaSyBiMuzZD8TahwWDJOAiTJciPnA2eybaVR0"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "555773019046-8t36tl4ar0g6vqkjibpucmra7bue509l.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "555773019046-1g8er5ph0mf4g7h1vbmc9b5q2olev41u.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.jgecNotice.RunnerTests"
}
}
]
"other_platform_oauth_client": []
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

package="com.example.anom_alert"
<uses-permission android:name="android.permission.INTERNET" />
<application
android:networkSecurityConfig="@xml/network_security_config"
Expand Down
13 changes: 12 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@

buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.9.0'
repositories {
google()
mavenCentral()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.gms:google-services:4.4.1"
classpath "com.android.tools.build:gradle:7.4.2"
//implementation "androidx.activity:activity:1.8.2"
}
}

plugins {
// ...

// Add the dependency for the Google services Gradle plugin
id 'com.google.gms.google-services' version '4.4.1' apply false

}

allprojects {
repositories {
google()
Expand Down
6 changes: 3 additions & 3 deletions ios/firebase_app_id_file.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"file_generated_by": "FlutterFire CLI",
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory",
"GOOGLE_APP_ID": "1:555773019046:ios:e54c712ae65ba0a790c567",
"FIREBASE_PROJECT_ID": "shashank-flutter",
"GCM_SENDER_ID": "555773019046"
"GOOGLE_APP_ID": "1:685258239678:ios:701475b3ddfa736ea878ef",
"FIREBASE_PROJECT_ID": "anom-alert",
"GCM_SENDER_ID": "685258239678"
}
19 changes: 19 additions & 0 deletions lib/api/firebase_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:anom_alert/firebase_options.dart';

class FirebaseApi {
Future<void> initNotifications() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;

NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: true,
carPlay: false,
badge: true,
criticalAlert: false,
provisional: false,
sound: true);
print('User granted permission: ${settings.authorizationStatus}');
}
}
39 changes: 14 additions & 25 deletions lib/firebase_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import 'package:flutter/foundation.dart'
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
return web;
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for web - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
Expand Down Expand Up @@ -46,34 +49,20 @@ class DefaultFirebaseOptions {
}
}

static const FirebaseOptions web = FirebaseOptions(
apiKey: 'AIzaSyACNG2SKCErW_hqIqhzwm1_8N7CRbu95wA',
appId: '1:555773019046:web:c695de34c85459d590c567',
messagingSenderId: '555773019046',
projectId: 'shashank-flutter',
authDomain: 'shashank-flutter.firebaseapp.com',
databaseURL: 'https://shashank-flutter-default-rtdb.firebaseio.com',
storageBucket: 'shashank-flutter.appspot.com',
);

static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyDmPZG9I0BfJhKxrQYFnAeU6p0tX4Ykovw',
appId: '1:555773019046:android:f5e6233cbe0aa03090c567',
messagingSenderId: '555773019046',
projectId: 'shashank-flutter',
databaseURL: 'https://shashank-flutter-default-rtdb.firebaseio.com',
storageBucket: 'shashank-flutter.appspot.com',
apiKey: 'AIzaSyBiMuzZD8TahwWDJOAiTJciPnA2eybaVR0',
appId: '1:685258239678:android:244ce9bcc7648f48a878ef',
messagingSenderId: '685258239678',
projectId: 'anom-alert',
storageBucket: 'anom-alert.appspot.com',
);

static const FirebaseOptions ios = FirebaseOptions(
apiKey: 'AIzaSyBWDaKQ9OfoeH9CziG5chF4mW7PZhdBtXM',
appId: '1:555773019046:ios:e54c712ae65ba0a790c567',
messagingSenderId: '555773019046',
projectId: 'shashank-flutter',
databaseURL: 'https://shashank-flutter-default-rtdb.firebaseio.com',
storageBucket: 'shashank-flutter.appspot.com',
androidClientId: '555773019046-7mlr7pml8ijqe5uh0jrl9h09bpnkdffc.apps.googleusercontent.com',
iosClientId: '555773019046-plu9n9oeicn8jh73ocu5qgm7cr029ere.apps.googleusercontent.com',
apiKey: 'AIzaSyDrgiPUa0bEImq6RGno6DpsP6cVrmHQnIU',
appId: '1:685258239678:ios:701475b3ddfa736ea878ef',
messagingSenderId: '685258239678',
projectId: 'anom-alert',
storageBucket: 'anom-alert.appspot.com',
iosBundleId: 'com.example.anomAlert',
);
}
51 changes: 43 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
import 'package:anom_alert/firebase_options.dart';
import 'package:anom_alert/models/camera.dart';
import 'package:anom_alert/screens/auth/main_page.dart';
import 'package:anom_alert/screens/auth/otp.dart';
import 'package:anom_alert/screens/camera_detail.dart';
import 'package:anom_alert/api/firebase_api.dart';
import 'package:anom_alert/screens/home_page.dart';
import 'package:anom_alert/screens/onboarding/onboarding_main.dart';
import 'package:anom_alert/theme.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:jwt_decoder/jwt_decoder.dart';
import 'screens/onboarding/onboarding_content.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

import 'screens/login_or_register.dart';

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print("Handling a background message: ${message.messageId}");
}

void main() async {
WidgetsFlutterBinding.ensureInitialized();

//await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

await FirebaseApi().initNotifications();
final token = await FirebaseMessaging.instance.getToken(vapidKey: "BOIgLBQCEnKa0V99S4gncnr_1mhgnS6aVKwV1AR_bWvSsESA8TR2_hHF4LESLfeirWoz8kt8RovfVPJTq7uxB_E");
print(token);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);


SharedPreferences preferences = await SharedPreferences.getInstance();

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print("Foreground Message Data: ${message.data}");
// Handle the message here
});

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print("Message opened app: ${message.data}");
// Handle the message here
});



// FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
// print("message : $message");
// //Navigator.pushReplacement(context, newRoute)
// });
//
// FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage? message){
// if(message!=null){
// print("message2 : $message");
// }
// });
//
// FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

runApp(ProviderScope(
child: MyApp(
token: preferences.getString("token"),
),
));
}



class MyApp extends StatelessWidget {
const MyApp({super.key, required this.token});

Expand Down
2 changes: 0 additions & 2 deletions lib/models/camera.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:flutter/cupertino.dart';

import 'recording.dart';

class Camera {
Expand Down
2 changes: 0 additions & 2 deletions lib/providers/camera_provider.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'dart:convert';

import 'package:anom_alert/providers/token_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';

import 'package:anom_alert/models/camera.dart';

Expand Down
2 changes: 0 additions & 2 deletions lib/screens/auth/register.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'dart:convert';

import 'package:anom_alert/providers/camera_provider.dart';
import 'package:anom_alert/screens/auth/register_error_messages.dart';
import 'package:anom_alert/screens/home_page.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http;
Expand Down
3 changes: 0 additions & 3 deletions lib/screens/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import 'package:anom_alert/providers/camera_provider.dart';
import 'package:anom_alert/providers/token_provider.dart';
import 'package:anom_alert/widgets/add_camera.dart';
import 'package:anom_alert/widgets/drawer.dart';
import 'package:anom_alert/widgets/new_camera.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:popover/popover.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class HomePage extends ConsumerStatefulWidget {
Expand Down
1 change: 0 additions & 1 deletion lib/widgets/add_camera.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:anom_alert/providers/camera_provider.dart';
import 'package:anom_alert/providers/token_provider.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down
6 changes: 6 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
import FlutterMacOS
import Foundation

import firebase_analytics
import firebase_auth
import firebase_core
import firebase_messaging
import flutter_local_notifications
import google_sign_in_ios
import path_provider_foundation
import shared_preferences_foundation
import sqflite
import video_player_avfoundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseAnalyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAnalyticsPlugin"))
FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FLTFirebaseMessagingPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseMessagingPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
Expand Down
Loading

0 comments on commit f5f6dc3

Please sign in to comment.