From 5645d7c07a0f584d5c1ee1569c92f93fae531759 Mon Sep 17 00:00:00 2001 From: bannzai Date: Sun, 17 Apr 2022 06:42:44 +0900 Subject: [PATCH 1/3] Fix call notification methods --- lib/domain/home/home_page.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/domain/home/home_page.dart b/lib/domain/home/home_page.dart index 6ab33333e0..83e012ff6c 100644 --- a/lib/domain/home/home_page.dart +++ b/lib/domain/home/home_page.dart @@ -43,7 +43,10 @@ class _HomePageState extends State initialIndex: _selectedIndex); _tabController.addListener(_handleTabSelection); - requestNotificationPermissions(); + Future(() async { + await requestNotificationPermissions(); + listenNotificationEvents(); + }); } @override From 3e5a86171e968c0e94868e5a7affdd2643d5e4d4 Mon Sep 17 00:00:00 2001 From: bannzai Date: Sun, 17 Apr 2022 06:43:45 +0900 Subject: [PATCH 2/3] Fix message service --- lib/domain/home/home_page.dart | 2 +- lib/service/push_notification.dart | 36 +++--------------------------- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/lib/domain/home/home_page.dart b/lib/domain/home/home_page.dart index 83e012ff6c..5dc4b244fa 100644 --- a/lib/domain/home/home_page.dart +++ b/lib/domain/home/home_page.dart @@ -62,7 +62,7 @@ class _HomePageState extends State Border(top: BorderSide(width: 1, color: PilllColors.border)), ), child: Ink( - color: PilllColors.bottomBar, + color: Color.fromARGB(255, 222, 211, 211), child: SafeArea( child: TabBar( controller: _tabController, diff --git a/lib/service/push_notification.dart b/lib/service/push_notification.dart index d01e1d8b4a..e210ec5108 100644 --- a/lib/service/push_notification.dart +++ b/lib/service/push_notification.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter/foundation.dart'; import 'package:pilll/analytics.dart'; import 'package:pilll/database/database.dart'; import 'package:pilll/service/user.dart'; @@ -20,7 +21,7 @@ Future requestNotificationPermissions() async { .setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true); } - callRegisterRemoteNotification(); + listenNotificationEvents(); final userService = UserService(DatabaseConnection(firebaseUser.uid)); userService.fetch().then((_) async { @@ -31,39 +32,8 @@ Future requestNotificationPermissions() async { } void listenNotificationEvents() { - FirebaseMessaging.onMessage.listen((event) { - print('onMessage: $event'); - }); - if (Platform.isAndroid) { - FirebaseMessaging.onBackgroundMessage(onBackgroundMessage); - } FirebaseMessaging.onMessageOpenedApp.listen((event) { analytics.logEvent(name: "opened_from_notification_on_background"); - print("onMessageOpenedApp: $event"); + debugPrint("onMessageOpenedApp: $event"); }); } - -void callRegisterRemoteNotification() { - if (Platform.isIOS) { - // NOTE: FirebaseMessaging.configure call [UIApplication registerForRemoteNotifcation] from native library. - // Reason for calling listenNotificationEvents, I won't overwrite defined to receive event via FirebaseMessaging().configure. - listenNotificationEvents(); - } -} - -Future onBackgroundMessage(RemoteMessage message) async { - print("Handling a background message ${message.data}"); - final messageData = message.data; - if (messageData.containsKey('data')) { - // データメッセージをハンドリング - final data = messageData['data']; - print("data: $data"); - } - - if (messageData.containsKey('notification')) { - // 通知メッセージをハンドリング - final notification = messageData['notification']; - print("notification: $notification"); - } - print('onBackground: $message'); -} From 6b2c3b224087dbf2506ffc0c345112cc13b2f8c3 Mon Sep 17 00:00:00 2001 From: bannzai Date: Sun, 17 Apr 2022 06:48:45 +0900 Subject: [PATCH 3/3] Replace --- lib/domain/home/home_page.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/domain/home/home_page.dart b/lib/domain/home/home_page.dart index 5dc4b244fa..83e012ff6c 100644 --- a/lib/domain/home/home_page.dart +++ b/lib/domain/home/home_page.dart @@ -62,7 +62,7 @@ class _HomePageState extends State Border(top: BorderSide(width: 1, color: PilllColors.border)), ), child: Ink( - color: Color.fromARGB(255, 222, 211, 211), + color: PilllColors.bottomBar, child: SafeArea( child: TabBar( controller: _tabController,