Closed realkalash closed 2 years ago
as i see in the screenshoot the source is "" which mean you are using this method in the wrong location
this method is to getting the notification that opened the app so you may use it before running your app
see this https://github.com/mo-ah-dawood/fcm_config/issues/15#issuecomment-909755385
Now I'm receiving a push notification with nulls and empty data
And this is happening in all cases when I click the push notification:
I'm receiving this
{senderId: null, category: null, collapseKey: null, contentAvailable: false, data: {}, from: null, messageId: null, messageType: null, mutableContent: false, notification: null, sentTime: null, threadId: null, ttl: null}
Instead of this
{senderId: null, category: null, collapseKey: null, contentAvailable: false, data: {twi_message_id: RU9d80739107f030d1361df9169cafa132, twi_body: {"message":{"sender_id":4170,"text":"Alex Kalashnikov\nSome message asfadfsdaggsfdfsf","type":"chat_message","chat_room_id":23291},"sound":1}}, from: 281770282794, messageId: 0:1656504411414293%aa724556f8fd7ecd, messageType: null, mutableContent: false, notification: null, sentTime: 1656504411350, threadId: null, ttl: 2419200}
Example of using FCMConfig.instance.messaging.getInitialMessage();
Future<void> main({bool integrationTesting = false}) async {
await FCMConfig.instance.init(defaultAndroidChannel: const AndroidNotificationChannel('0', '0'));
final clickedPushNotificationLocal = await FCMConfig.instance.local.getInitialMessage();
final clickedPushNotificationMessaging = await FCMConfig.instance.messaging.getInitialMessage();
if (kDebugMode) {
/// Receiving push notifications with empty data
print('🔔 Clicked push notification local: ${clickedPushNotificationLocal?.toMap()}');
/// Receiving null
print('🔔🔔 Clicked push notification Messaging: ${clickedPushNotificationMessaging?.toMap()}');
}
await runZonedGuarded(
() async {
runApp(
riverpod.UncontrolledProviderScope(
container: _providerContainer,
child: const ProviderWidget(),
),
);
}
);
}
Example of using mixin
class TabPage extends StatefulWidget {
const TabPage({Key? key}) : super(key: key);
@override
_TabPageState createState() => _TabPageState();
}
class _TabPageState extends State<TabPage>
with SingleTickerProviderStateMixin, FCMNotificationClickMixin {
@override
Widget build(BuildContext context) {
return Scaffold(
/// other code
);
}
/// On push notification click
@override
void onClick(RemoteMessage notification) {
if (kDebugMode) {
/// Receiving push notifications with empty data
print('🔔 Clicked push notification from tab page: ${notification.toMap()}');
}
}
}
PS: The service that sends these messages is Twilio.
It looks like it's something wrong on a deeper level. I've implemented the flutter local notifications plugin instead, and it does not see any data in Push notifications also.
It works fine when the app is open, but when I open it from the notification, it throws an error. Example of the PN:
{senderId: null, category: null, collapseKey: null, contentAvailable: false, data: {twi_message_id: RUb5c43c3edb424986c02256d936eff86f, twi_body: {"message":{"sender_id":4170,"text":"Alex2 K, Alex Kalashnikov\n123\n ","type":"chat_message","chat_room_id":23517},"sound":1}}, from: 281770282794, messageId: 0:1659539439408925%aa724556f9fd7ecd, messageType: null, mutableContent: false, notification: null, sentTime: 1659539439369, threadId: null, ttl: 2419200}
PS: The service that sends these messages is Twilio.