You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
`import 'dart:typed_data';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:stepcom/Task/Api/api.dart';
import '../Auth/api/api.dart';
import '../Discussion/Api/api.dart';
import '../Discussion/chat.dart';
import '../Home/home_screens.dart';
import '../Task/task_details.dart';
import '../globalVariable.dart';
int id = 0;
AndroidNotificationChannel channel = const AndroidNotificationChannel(
'Field360', // id
'Field360', // title
importance: Importance.max,
enableLights: true,
playSound: true,
);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
class FirebaseMessageApi {
/// Initialization
static Future initialize() async {
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
}
/// Handle received messages
static void handleMessage([BuildContext? context]) {
FirebaseMessaging.onMessageOpenedApp.listen((
RemoteMessage message,
) async {
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
if (notification != null && android != null) {
customLog("onMessageOpenedApp Body :: ${notification.body}");
customLog("onMessageOpenedApp Data :: ${message.data}");
String payload = message.data['click_action'] ?? '';
customLog("payload :: ${message.data['click_action'] ?? ''}");
// if (payload == 'click_action') {
String input = message.data['click_action'] ?? '';
String input3 = message.data['project_id'] ?? '';
String input2 = message.data['timestamp'] ?? '';
String image = message.data['image_url'] ?? '';
}
static Future _getByteArrayFromUrl(String url) async {
final http.Response response = await http.get(Uri.parse(url));
return response.bodyBytes;
}
static Future subscribeTopic(String topic) async {
customPrint("subscribeTopic :: $topic");
await FirebaseMessaging.instance.subscribeToTopic(topic);
}
static Future unSubscribeTopic(String topic) async {
customPrint("unSubscribeTopic :: $topic");
await FirebaseMessaging.instance.unsubscribeFromTopic(topic);
}
static Future showBigPictureNotificationURL(notification, image) async {
customPrint("showBigPictureNotificationURL :: ${notification.hashCode}");
final ByteArrayAndroidBitmap largeIcon =
ByteArrayAndroidBitmap(await _getByteArrayFromUrl(image));
final ByteArrayAndroidBitmap bigPicture =
ByteArrayAndroidBitmap(await _getByteArrayFromUrl(image));
final BigPictureStyleInformation bigPictureStyleInformation =
BigPictureStyleInformation(bigPicture,
largeIcon: largeIcon,
contentTitle: notification.title,
htmlFormatContentTitle: true,
summaryText: notification.body,
htmlFormatSummaryText: true);
final AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(channel.id, channel.name,
channelDescription: channel.description,
icon: "app_icon",
styleInformation: bigPictureStyleInformation);
final NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await flutterLocalNotificationsPlugin.cancel(101);
await flutterLocalNotificationsPlugin.show(
0, notification.title, notification.body, notificationDetails);
}
}`
is there any way to stop that extra notification that firebase triggered automatically??
Beta Was this translation helpful? Give feedback.
All reactions