From e4364cfb1e8977d108dbd654113283ccc51700c1 Mon Sep 17 00:00:00 2001 From: emkartal1 Date: Wed, 2 Aug 2023 20:44:13 +0200 Subject: [PATCH] Starting Notification --- Sources/justMUSIC/android/app/build.gradle | 1 + Sources/justMUSIC/lib/main.dart | 2 ++ .../lib/services/NotificationService.dart | 18 ++++++++++++++ Sources/justMUSIC/pubspec.lock | 24 +++++++++++++++++++ Sources/justMUSIC/pubspec.yaml | 1 + 5 files changed, 46 insertions(+) create mode 100644 Sources/justMUSIC/lib/services/NotificationService.dart diff --git a/Sources/justMUSIC/android/app/build.gradle b/Sources/justMUSIC/android/app/build.gradle index 97e5ae2..f318bc7 100644 --- a/Sources/justMUSIC/android/app/build.gradle +++ b/Sources/justMUSIC/android/app/build.gradle @@ -24,6 +24,7 @@ if (flutterVersionName == null) { apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'com.google.gms.google-services' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { diff --git a/Sources/justMUSIC/lib/main.dart b/Sources/justMUSIC/lib/main.dart index 7baa4cb..b9448c7 100644 --- a/Sources/justMUSIC/lib/main.dart +++ b/Sources/justMUSIC/lib/main.dart @@ -16,6 +16,7 @@ import 'package:justmusic/screens/post_screen.dart'; import 'package:justmusic/screens/profile_screen.dart'; import 'package:justmusic/screens/registration_screen.dart'; import 'package:justmusic/screens/welcome_screen.dart'; +import 'package:justmusic/services/NotificationService.dart'; import 'package:justmusic/values/constants.dart'; import 'package:justmusic/view_model/MusicViewModel.dart'; import 'package:justmusic/view_model/PostViewModel.dart'; @@ -28,6 +29,7 @@ Future main() async { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); + await NotificationService().initNotifications(); runApp(const MyApp()); } diff --git a/Sources/justMUSIC/lib/services/NotificationService.dart b/Sources/justMUSIC/lib/services/NotificationService.dart new file mode 100644 index 0000000..8582741 --- /dev/null +++ b/Sources/justMUSIC/lib/services/NotificationService.dart @@ -0,0 +1,18 @@ +import 'package:firebase_messaging/firebase_messaging.dart'; + +class NotificationService { + final _firebaseMessaging = FirebaseMessaging.instance; + + Future handleBackgroundMessage(RemoteMessage message) async { + print('Title: ${message.notification?.title}'); + print('Body: ${message.notification?.body}'); + print('Payload: ${message.data}'); + } + + Future initNotifications() async { + await _firebaseMessaging.requestPermission(); + final token = await _firebaseMessaging.getToken(); + print("Grrrpaw:"+token!); + //FirebaseMessaging.onBackgroundMessage(handleBackgroundMessage); + } +} \ No newline at end of file diff --git a/Sources/justMUSIC/pubspec.lock b/Sources/justMUSIC/pubspec.lock index 30973dd..9fc8484 100644 --- a/Sources/justMUSIC/pubspec.lock +++ b/Sources/justMUSIC/pubspec.lock @@ -337,6 +337,30 @@ packages: url: "https://pub.dev" source: hosted version: "2.6.0" + firebase_messaging: + dependency: "direct main" + description: + name: firebase_messaging + sha256: "8ac91d83a028eef050de770f1dc98421e215714d245f34de7b154d436676fbd0" + url: "https://pub.dev" + source: hosted + version: "14.6.5" + firebase_messaging_platform_interface: + dependency: transitive + description: + name: firebase_messaging_platform_interface + sha256: b2995e3640efb646e9ebf0e2fa50dea84895f0746a31d7e3af0e5e009a533a1a + url: "https://pub.dev" + source: hosted + version: "4.5.4" + firebase_messaging_web: + dependency: transitive + description: + name: firebase_messaging_web + sha256: "5d8446a28339124a2cb4f57a6ca454a3aca7d0c5c0cdfa5707afb192f7c830a7" + url: "https://pub.dev" + source: hosted + version: "3.5.4" firebase_storage: dependency: "direct main" description: diff --git a/Sources/justMUSIC/pubspec.yaml b/Sources/justMUSIC/pubspec.yaml index d56b47b..98020d4 100644 --- a/Sources/justMUSIC/pubspec.yaml +++ b/Sources/justMUSIC/pubspec.yaml @@ -72,6 +72,7 @@ dependencies: animations: ^2.0.7 flutter_svg: ^2.0.7 flutter_keyboard_visibility: ^5.4.1 + firebase_messaging: ^14.6.5 dev_dependencies: flutter_test: